CSC151 2007S, Class 16: Local Bindings Admin: * Assigned: Exam 1 * Due: HW 7 * I've made a few short adjustments to the syllabus. * Today's outline is fairly long; I don't intend to go into that much detail in class. * Reading for Monday: Preconditions and Postconditions. Overview: * Things we might talk about * Why name things. * Naming things with let. * Naming things with let*. * Naming procedures. * Q & A. * Lab. Issue in all algorithms: We want to name values, including computed values * define provides a perfectly nice way to name things * Name values: (define time-of-day 1016) * Name computed values: (define ave-hw (/ (sum hw) (length hw))) * name procedures (define id (lambda (x) x)) * Name recursive procedures (define factorial (lambda (n) (if (= 0 n) 1 (* n (factorial (- n 1)))))) * At times, we want to name more than what is nameable with define * We want to name a value *in the middle of a procedure* * Define not formally allowed in that context * We want a name that no one else can change * Define provides a "globally accessible" name We need another way to name values: let (let ((name value) (name value) (name value)) exp) * exp can use the names * Nothing else can use those names (define silly (lambda (a b c) (sqrt (+ (* a a) (* b b) (* c c))))) (define silly (lambda (a b c) (let ((square (lambda (x) (* x x)))) (sqrt (+ (square a) (square b) (square c))))))