CSC302 2007S, Class 27: Mid-Semester Examination, Concluded
Admin:
* As you can tell, I've rearranged the syllabus again.
* If you have not submitted your comments on the Ruby readings, please do so ASAP.
* EC for participating in Hoofin' It.
* CS Table Monday
Overview:
* Problem 3, Concluded.
* Problem 4.
* Presentations.
/Problem 3: Evaluating Lambda/
((lambda formals body) actuals)
Technique
0. Make sure that it has the correct form
1. Evaluate all of the actuals, creating a list of evaluated actuals
(_l_evlis)
2. Make a list of formal/actual pairs to represent intended bindings
in the body (_l_makepairs)
3. Append that to the front of the environment
(_l_append)
4. Evaluate the body in the new environment
* What if we're just naming the lambda, instead of evaluating it.
Some tests
leval '((lambda (x) 2) 5)'
* Expect 2
leval '((lambda (x) (cons x x)) 5)'
* Expect (5 . 5)
leval '((lambda (x y) (cons x (cons y y))) 3 4)'
* Expect (3 . (4 . 4))
leval '((lambda () 2))'
* Expect 2
leval '((lambda (x) (cons x x)) 5 6)'
* Expect "You bozo, you gave the wrong number of paramters. The blue screen of death will now appear."
leval '((lambda (x) (cons x x)))'
* Similar
leval '((lambda (x) (cons x 3)) ((lambda (x) (cons x x)) 5))'
* Expect ((5 . 5) . 3)
leval '(define a (lambda (x) 2))' '(a 5)'
* Expect that it returns 2
What's the difference between (allocate_pair (a b c) (4 5 6))
and (make_pairs (a b c) (4 5 6))?
allocate_pairs returns ((a b c) . (4 5 6))
make_pairs returns ((a . 4) (b . 5) (c . 6))