Skip to content

Instantly share code, notes, and snippets.

@palladin
Last active September 25, 2021 17:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save palladin/c5fc4bc284e7bcb2f01c5d52607b9f68 to your computer and use it in GitHub Desktop.
Save palladin/c5fc4bc284e7bcb2f01c5d52607b9f68 to your computer and use it in GitHub Desktop.
A meta-circular interpreter for Lambda Calculus
(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