recitation 1: scheme expressions ---------------------------------------------------------------- primitive expressions self-evaluating expressions (constants) boolean: #t, #f numbers: 0, 1, -5, 6.001, 76120398235983942, .... strings: "hello", "world", "6.001", ... built-in procedures: +, *, sqrt, odd?, zero?, .. variables (check lookup table) - initial: defines built-in procedures - add to lookup table with define - means of abstraction compound expressions (things in parens) combinations - prefix notation (vs. postfix or infix) - variable number of arguments - expressions as trees special forms define -global definitions and or if lambda ---------------------------------------------------------------- identifiers - can't start with a number - can't have white-space - can be upper/lower case reserved keywords =>, and, begin, case, cond, define, delay, else, if, lambda, let, let*, letrec, quasiquote, quote, set! unquote, unquote-splicing variables - In Scheme we don't have to declare the type (e.g. int, boolean, floating point, ...) use ";" for comments ---------------------------------------------------------------- Rules for evaluation 1. If self-evaluating, return value. 2. If a name, return value associated with name in environment. 3. If a special form, do something special. 4. If a combination, then a. Evaluate all of the subexpressions of combination (in any order) b. Apply the operator to the values of the operands (arguments) and return result ---------------------------------------------------------------- Mantra Review 1. Every expression has a value (except for errors, infinite loops and the define special form) 2. To find the value of a combination, * Find values of all subexpressions in any order * Apply the value of the first to the values of the rest 3. The value of a lambda expression is a procedure ---------------------------------------------------------------- To find the value of a COMBINATION: a. first, find the value of the ___________ b, then, APPLY the value of the ________ to the ___________ ---------------------------------------------------------------- (* 2 3) => (*2 3) => ((*2 3)) => (define a 5) => (define b (+ a 2)) => (define a 3) => a => b => (a) => (define define 4) => (and #t) => (and #t #f) => (and #t #f (4)) => (define and 5) =>