CSC151 2009F, Class 20: Naming Local Values or ... The day everything you've learned about parenthesization goes out the window. Admin: * I will not have office hours today. Sorry. * Please keep your partners from Monday. * Assignment 5 is now ready. * EC for attending some part of the Rosenfield anniversary symposium on Thursday. * Don't forget about the history of programming languages talk at noon on Friday in 3821. * Reading for Friday: Boolean Values and Predicate Procedures. * Quiz Friday: Turtles, for-each, let, plus past concepts * Firefox seems to be having some problems for some people. Ask me for help. Overview: * Reminder of algorithm components * Parenthesization in Scheme. * Naming things with let. * Naming things with let*. * Naming procedures. * Lab. Algorithm components: * Basic values and operations on those values * [UM ness, the universal machine and its application to algorithms] * Procedures and functions: Parameterized sequences of operations * [Defined with lambda in Scheme] * [Parentheses, at least in Scheme] * Ways to name values * Ways to sequence operations * Loops: Repeat operations * Scheme: (repeat n action parameter) * Scheme: (map operation list) * [Scheme: (iota n) - make a list] * (for-each operation list) * Conditionals: Choose between operations Paranetheses (foo bar baz) * If typed by the user, likely to be "apply procedure foo to bar and baz" * If used in sectioning or compose, it could be "build a procedure" * If foo is "define" it could be the indication taht we could use the name bar for baz. * If typed by the computer, likely to be "the list of the symbols foo, bar, and baz" * If typed by the user as part of (lambda (foo bar baz) ...) foo bar and baz name parameters Problem: Want to name values (as with define) but * Want to keep the names safe from other people * Want them to have limited lifetimes Define doesn't suffice The solution: let NOT THE FORM (let name value expression) THE REAL FORM (let ((name value) (another-name another-value) ...) expression) Where do we put this in a procedure (define rgb-grey (lambda (rgb) (rgb-new (/ (+ (rgb-red rgb) (rgb-green rgb) (rgb-blue rgb)) 3) (/ (+ (rgb-red rgb) (rgb-green rgb) (rgb-blue rgb)) 3) (/ (+ (rgb-red rgb) (rgb-green rgb) (rgb-blue rgb)) 3)))) (define rgb-grey (lambda (rgb) (let ((brightness (/ (+ (rgb-red rgb) (rgb-green rgb) (rgb-blue rgb)) 3))) (rgb-new brightness brightness brightness)))) (define radians-to-degrees (let ((conversion-factor (/ 180 pi))) (lambda (rad) (* rad conversion-factor))))