CSC302 2007S, Class 13: Why LISP? Admin: * I'm working on an essay on what we did last week. It should be ready by tomorrow. (It's optional reading, but it should help.) * I'm disappointed at how few of you came to Friday's lunch. * EC for Thursday's convo Reframing Disability: New Ways of Seeing and Representing Disability Overview: * Why lisp? * Graham's differences. * Other issues. Claim: People who program in LISP are wild fanatics (about the language) Why? * Concise! * Tries to look like Math, and math is concise * Higher-order procedures permit very concise definitions (define addtwo (l-s + 2)) * Don't bother to type variables * Program notation as "trees" formed by parenthesization * "Powerful" - Permits you to write complicated code more quickly * Concise * Not a lot of crap to get in your way * Self-modifying code, including macros * Macros take program code as input and output program code (more precisely, s-expressions) * Code and data are nearly indistinguishable (+ 1 2 3 4 5) * Code: apply the function + to the parameters 1 2 3 4 5 * Data: A six-element list * Polymorphic - Generic * Once you write reverse once, it works for every list * "Long Lived" - Has existed since 1960, and is used about as much now as it was in 1960. * Easy to learn (or to relearn) * Not a lot of extra stuff to remember * Nerdy * Out of the mainstream * Kinda difficult, in that your brain must think differently * More like a math geek * Outside of the von Neumann model What are the "problems" with Lisp and Scheme * Dynamic typing * Do you trust the programmer to write correct code? * What barriers do you insert to help ensure that the programmer writes correct code? * Lack of libraries? * Standard vs. "Find one" * List-based * Locality * Adds gc requirements * Sharing decision effects need for purity * Random access is not O(1) * Pure? * Sometimes we like side effects * Need to think differently * And not everyone can do so * Need to understand costs ; (iota n) => (0 1 2 ... n-1) (define iota (lambda (n) (if (zero? n) null (append (iota (- n 1)) (list (- n 1)))))) * Lisp is slower or less efficient than many languages What made Lisp different? * Garbage collection - Allocated memory that is no longer in use is automatically reclaimed * Early technique: Reference counting * Early technique: Mark and sweep * Start with a list of things known to be available * Follow pointers, marking things as "pointed to" * Copy pointed-to things elsewhere * Update pointers * Recursion * Conditionals Stuff in the higher numbers * Code and Data identical - sexpressions * Evaluation model: read, eval, print