* the SASL interpreter ** thunks = expression + environment *** printing thunks *** evaluation * real SASL ** if syntax ** pattern matching (as in ML) ** ZF expressions * lambda calculus ** key idea: using thunks to represent data and control ** booleans and if, p. 179 ** lists, p. 179 ** the calculus, p. 187 *** substitution **** free variables, Fv ---------- Fv(x) = {x} Fv(lambda (x) e) = Fv(e) - {x} Fv(e e') = Fv(e) union Fv(e') ---------- **** bound variables ------------------ [alpha] (lambda (x) U) = (lambda (y) [y/x]U), if y is free in U ------------------ **** syntactic substitution ------------ [e/x]x == e [e/x]y == y if not(y == x) [e/x](e1 e2) == (([e/x]e1) ([e/x]e2)) [e/x](lambda (y) e') == (lambda (y) [e/x]e') if not(y == x), and not(y in Fv(e)) ------------ *** equational theory **** beta rule: application ---------------------- [beta] ((lambda (x) M) N) ==> [N/x]M ------------------ ------------------ e.g.: ((((lambda (f) (lambda (x) (lambda (y) (f x y)))) +) 1) 2) ==> ((((lambda (x) (lambda (y) (+ x y)))) 1) 2) ==> ((lambda (y) (+ 1 y)) 2) ==> (+ 1 2) ------------------ ------------ (((lambda (y) (lambda (x) y)) 27) (/ 3 0)) ==> ((lambda (x) 27) (/ 3 0)) ==> 27 ------------ **** delta rule: using primitive operations from the environment --------------------- [delta] (f e1 e2) ==> f(e1,e2), if e1 and e2 are integers, and f is not bound by surrounding expr. --------------------- **** mu rule: using defined names from the environment --------------------- [delta] f ==> e, if f is not bound by surrounding expr, and f is bound to e in global environment --------------------- **** eta rule: an optimization --------------- [eta] (lambda (x) (e x)) ==> e, if x not in Fv(e) --------------- --------------- e.g.: (set with-characteristic (lambda (f) (lambda (x) (f x)))) ==> (set with-characteristic (lambda (f) f)) e.g.: (set member? (lambda (s) (lambda (x) (s x)))) ==> (set member? (lambda (s) s)) --------------- ** summary *** referential transparency: equals can be replace by equals *** why give up referential transparency?