Direct Style from Monadic
Style and Back , a printable
version, and source (just load
it).
Assignment for April 11th class.
Here is r* a lambda-calculus reducer.
(define r*
(lambda (e)
(let ((t (r0 e (lambda (hole) hole))))
(cond
((equal? t e) t)
(else (r* t))))))
(define r0
(lambda (e ctx)
(match e
(,x (guard (symbol? x)) (ctx x))
((lambda (,id) ,body)
(r0 body (lambda (hole) (ctx `(lambda (,id) ,hole)))))
;;; in Scheme we don't go under the lambda, but here we do
;;; just for the fun of it.
((,rator ,rand)
(match rator
(,f (guard (symbol? f)) (r0 rand (lambda (hole) (ctx `(,f ,hole)))))
((lambda (,id) ,body) (ctx (beta-subst rand id body)))
(,else (r0 rator (lambda (hole) (ctx `(,hole ,rand))))))))
;;; We have chosen to evaluate the rator first.
;;; obviously this is arbitrary.
Grab your body[id <- rand] from last semester's handout to implement
(beta-subst rand id body)
Finish implementing this reducer by defining beta-subst (see Stoy)
and then try to mini-kanrenize it.
... Dan