CSC153, Class 18: More Higher-Order Procedures Overview: * Operator Sections * Currying * Lab * Reflection Notes: * About Produces and Postconditions * More questions on exam 1? * Read Bailey * Comments on Mr. Stone's book? * Making Delete work the way you want * HW1 graded. Writeup 2 not graded. ---------------------------------------- Defining procedures (define name (lambda (param1 ... paramn) body)) (define (name param1 ... paramn) body) ---------------------------------------- Operator Sections: * Observation: We often want to fill in some of the parameters to a procedure, but not all of them. "Whoops, I really should add 10 to everyone's grade on the exam" (map "add 10" list-of-grades) (map (lambda (x) (+ 10 x)) list-of-grades) (define left-section (lambda (binary-procedure first-param) (lambda (second-param) (binary-procedure first-param second-param)))) (map (left-section + 10) list-of-grades) (define add10 (left-section + 10)) REMINDER: Explain cute If generalization is your cup of tea, you might want to define a variant of left-section that takes an N-ary procedurea and M of its parameters, and returns an (N-M)-ary procedure This generalization is cute. (cute NAME_OF_PROCEDURE filled-in-argument <> ...) (define add10 (cute + 10 <>)) (define sub5 (cute - <> 5)) (define square-list (cute map (lambda (x) (* x x)) <>)) ---------------------------------------- Currying: We'll discuss it later. ---------------------------------------- Reflection: For right-insert, your base case should be "does the list have only one element" and not "does the list have no elements"