Created
March 12, 2015 16:25
-
-
Save orchid-hybrid/9004aa8c8e56cf2071e5 to your computer and use it in GitHub Desktop.
defunctionalize NbE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; http://www.brics.dk/RS/01/23/BRICS-RS-01-23.pdf | |
(define (eval term env) | |
(match term | |
((symbol? s) (lookup s env)) | |
(`(lambda (,(symbol? v)) ,body) (lambda (x) (eval body (cons (cons v x) env)))) | |
(`(,m ,n) ((eval m env) (eval n env))))) | |
;; Defunctionalize ==> | |
(define (apply l x) | |
(match l | |
(`(closure ,body ,v ,env) (eval body (cons (cons v x) env))))) | |
(define (eval term env) | |
(match term | |
((symbol? s) (lookup s env)) | |
(`(lambda (,(symbol? v)) ,body) `(closure ,body ,v ,env)) | |
(`(,m ,n) (apply (eval m env) (eval n env))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment