CS302 2007S, Class 08: Higher-Order Graphics Admin: * I got the talks wrong Tomorrow's talk is on the Automation of Athletic Recruiting. * Are there questions on HW3? * Friday's reading is also online (Representing Images). * Three readings distributed for next Monday. * "What Made Lisp Different" subsetof "Revenge of the Nerds" * Comment on both. (For RotN, comment on something other than WMLD) * Slight rearrangement of syllabus Overview: * Thinking functionally. * The basics of higher-order procedures. * Lab. /What is Functional Programming?/ * Not as linear as procedural programming * We don't have to follow a sequence of operations * (proc param0 param1 param2 ... paramn) * A procedural programmer would be likely to do a sequence of function calls * A real functional programmer would simply nest * Functions are "first class" values * They can be parameters to other procedures * They can be returned from other procedures * They can be created "dynamically" * Scheme is more "mathematical" - "pure" * In C and Java, the model is that function calls have side effects (and are done for the side effects) * In a well-designed functional language, a well-designed procedure is called only for its return value * Answers are reproducible * Analysis is easier /START OF DETOUR ON PURITY/ a = 10; foo(); print(a); public class Variable { int contents; public void set(int newval) { this.contents = newval; } public int get() { return this.contents; } public String toString() { return Integer.toString(this.contents); } } public void silly(Variable a, Variable b) { a.set(10); b.set(20); out.println(a); } /END OF DETOUR ON PURITY/ * Built-in symbol type * Faster comparison (define what-should-i-do (lambda (day) (if (member day (list 'sunday 'tuesday 'thursday)) "Send Sam a reflection on the reading NOW" "Do the reading, so you can send sam a reflection"))) in C typdef days enum (monday, tuesday, wednesday, thursday, friday, saturday, sunday); switch (day) { case sunday: case tuesday: case thursday: return "Send reflection"; break; case default: return "Read"; break; } * Garbage collection * Code and data are "indistinguishable" * You can execute data * You can treat code as data /HOP - A Key Functional Concept/ /Lab/