recitation 21: more evaluation
=========================================================================
lexical scoping (static scoping): look up free variables in
procedure's surrounding lexical environment -- REGULAR SCHEME
dynamic scoping: look up free variables in caller's environment,
don't need env pointer any more!!
(define a 1)
(define (b) a)
(define (c a) (lambda (a) (b)))
(define d (c 2))
(d 3)
* draw environment diagram to execute with lexical scoping
* draw environment diagram to execute with dynamic scoping
=========================================================================
semantics: what the language *means*, model of computation
syntax: particulars of *writing* expressions
abstracted by the detectors & accessors
building our own evaluator allows us to modify the syntax and/or
semantics of the language
semantic implementation vs. syntactic transformation (desugar it)
* write a syntactic translator for let*
* write a semantic implementation for let*
=========================================================================
* Write an expression to return the following streams:
[ 1 1 1 1 ... ]
[ 1 2 1 2 ... ]
[ 1 2 3 4 ... ]
[ 1 1 2 3 5 8 13 ... ]
* What stream do the following expressions return?
(define alt (cons-stream 0 (interleave integers alt)))
* Write a function that merges two ordered streams of integers, removing
duplicates as it goes. Assume that each individual stream contains no
duplicates.
(define (merge-stream s1 s2)
* Write a function that removes duplicates from an unordered stream.
(you may want to use stream-filter)
(define (remove-duplicates s)