Skip to content

Instantly share code, notes, and snippets.

@orchid-hybrid
Created March 12, 2015 16:25
Show Gist options
  • Save orchid-hybrid/9004aa8c8e56cf2071e5 to your computer and use it in GitHub Desktop.
Save orchid-hybrid/9004aa8c8e56cf2071e5 to your computer and use it in GitHub Desktop.
defunctionalize NbE
;; 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