// 1. declare function // 2. use function, pass values // 2. use function, pass values Conversion from Regular Function to Lambda #2 Regular Function Lambda Function (define (countNegative aList) (define (countNegative2 aList) (cond (length (filter (lambda (x) (< x 0)) aList))) ((null? aList) 0) ((not (list? aList)) (if (< aList 0) 1 0)) Both filter and length are HIGHER order functions (pre-built) (else (apply + (cons (countNegative (car aList)) Filter function requires 2 parameters, the algorithm and the list (map countNegative (cdr aList))))))) Sources Dr. Dylan Shell 314 notes Gambit Scheme Manual Basics of Function Programming Total Functions
// 1. declare function // 2. use function, pass values // 2. use function, pass values Conversion from Regular Function to Lambda #2 Regular Function Lambda Function (define (countNegative aList) (cond ((null? aList) 0) ((not (list? aList)) (if (< aList 0) 1 0)) (else (apply + (cons (countNegative (car aList)) (map countNegative (cdr aList))))))) (define (countNegative2 aList) (length (filter (lambda (x) (< x 0)) aList))) Both filter and length are HIGHER order functions (pre-built) Filter function requires 2 parameters, the algorithm and the list Sources Dr. Dylan Shell 314 notes Gambit Scheme Manual Basics of Function Programming Total Functions
Function%20design%20Basics%20in%20Programming%20Languages.docx