Summary: How to work a mystery problem, as in chapter 7 Keywords: lambda, =, mystery This is something I probably should have done in class, and the student management team pointed out. Consider the following problem form the first chapter 7 test... (let ((me (lambda (proc) (proc #t))) (you (lambda (proc) (proc #f))) (us (lambda (x y) (lambda (b) (if b x y))))) (writeln "a: " (me (us 1 2))) (writeln "b: " (you (us 1 2))) (writeln "c: " (me (you (us 1 (us 2 3)))))) One way to work this is to draw the diagram of the environments, etc. But there is a better way. The better way is to see that each lambda definition gives an equational rule, and then to use those rules to solve the problem. In this case we have to figure out equational rules for the procedures me, you, and us. Consider us first; it works as follows: ((us x y) b) = (if b x y) How can you tell that? The fast way is to get that from the definition: us = (lambda (x y) (lambda (b) (if b x y))) so (us x y) = (lambda (b) (if b x y)) and ((us x y) b) = (if b x y) Now do the same thing for me and you: me = (lambda (proc) (proc #t)) so (me proc) = (proc #t) and you = (lambda (proc) (proc #f)) so (you proc) = (proc #f) This may not seem to be getting us very far, but wait! Let's consider what we have to do. We have to find the answer to questions of the form (me (us 1 2)) Let "(us 1 2)" play the role of "proc" above. Then we have (me (us 1 2) = ((us 1 2) #t) = (if #t 1 2) = 1 I leave it to you to work the rest. However I wish to point out the following derived equations (me (us x y)) = x (you (us x y)) = y (us (me (us x y)) (you (us x y))) = (us x y) Note the similarity between this an the following: (car (cons x y)) = x (cdr (cons x y)) = y (cons (car (cons x y)) (cdr (cons x y))) = (cons x y) So you can think of me as car, you as cdr, and us as cons! The significance of this is that we can do car, cdr, and cons using just lambda! It turns out that lambda can do everything we need (but not very fast).