ML - Functional Programming Chapter 13 1 Functional Programming Style Write many small functions(2-liners Each loop corresponds to 1 function No

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 4101: Programming Languages 1 1 Functional Programming Chapter 13 2 Functional Programming Style Write many small functions (2-liners) Each loop corresponds to 1 function No assignment, only function calls Write base cases of recursion case for empty list, maybe for atoms maybe case for singleton list Write recursive cases case(s) for nonempty list 3 Example: Nesting of Parentheses Base case empty list: 1 Base case atoms: 0 Recursive case: max (1+car, cdr) Finished function (define (nest x) (cond ((null? x) 1) ((not (pair? x)) 0) (else (max (+ 1 (nest (car x))) (nest (cdr x))))))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSC 4101: Programming Languages 2 4 Example: Integer Equation Given: lengths l1, l2, l3, len Can len be constructed from pieces of lengths l1, l2, and l3? (define (test len l1 l2 l3) (if (<= len 0) (= len 0) (or (test (- len l1) l1 l2 l3) (test (- len l2) l1 l2 l3) (test (- len l3) l1 l2 l3)))) 5 ML vs. Scheme Scheme primitive syntax dynamically typed Lists as built-in data type
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/31/2011 for the course CSC 4101 taught by Professor Kraft,d during the Fall '08 term at LSU.

Page1 / 6

ML - Functional Programming Chapter 13 1 Functional Programming Style Write many small functions(2-liners Each loop corresponds to 1 function No

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online