{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ML - Functional Programming Chapter 13 1 Functional...

Info icon This 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))))))
Image of page 1

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

View Full Document Right Arrow Icon