[ prog / sol / mona ]

prog


Marvin Minsky - The Beauty of the Lisp Language [Part 2]

22 2020-10-15 06:12

>>18

He writes more than this then deletes some of it. This is the minimum needed to run his "proof it works" example.

(define eval-expr
  (lambda (expr env)
    (pmatch expr
      [,n (guard (number? n))
       n]
      [,x (guard (symbol? x))
       (env x)]
      [(lambda (,x) ,body)
       (lambda (arg)
         (eval-expr body (lambda (y)
                           (if (eq? x y)
                               arg
                               (env y)))))]
      [(,rator ,rand)
       ((eval-expr rator env)
        (eval-expr rand env))])))

pmatch.scm is loaded but not made available. We can make an educated guess that this[0] is pmatch.scm.

His "proof it works" example using chez.

> (load "pmatch.scm")
> (eval-expr '((lambda (x) x) 5) (lambda (y) (error 'lookup "unbound")))
5

[0] https://github.com/webyrd/quines/blob/master/pmatch.scm

24


VIP:

do not edit these