Last active
September 25, 2021 17:52
-
-
Save palladin/c5fc4bc284e7bcb2f01c5d52607b9f68 to your computer and use it in GitHub Desktop.
A meta-circular interpreter for Lambda Calculus
This file contains hidden or 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
(require '[clojure.core.match :refer [match]]) | |
(defn extend [k v l] | |
(fn [k'] | |
(if (= k k') v (l k')))) | |
(def empty (fn [k'] (throw (Exception. "oups")))) | |
(defn eval [e env] | |
(match [e] | |
[(['lambda ([param] :seq) body] :seq)] | |
(fn [v] (eval body (extend param v env))) | |
[([e1 e2] :seq)] | |
((eval e1 env) (eval e2 env)) | |
[x] (env x) )) | |
(eval '((lambda (x) (x x)) (lambda (x) (x x))) empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment