Skip to content

Instantly share code, notes, and snippets.

@msszczep
Created July 22, 2014 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msszczep/12168573f29159e86dfc to your computer and use it in GitHub Desktop.
Save msszczep/12168573f29159e86dfc to your computer and use it in GitHub Desktop.
Build an evaluator in Clojure (Lambda Jam 2014)
; variable evaluation: find and substitute
; look for Var X in B and substitute a
; environment, symbol
(def MyEnv {"One" 1
"Two" 2
"Three" 3
"MyAdd" +})
(defn MyEval [[term f & args]]
(cond
(= term "MyApply") (apply (MyEnv f) (map MyEnv args))
:else "You Failed"))
(MyEval ["MyApply" "MyAdd" "One" "Two" "TwoA"])
(MyEval ["cheese" "MyAdd" "One" "Two" "Three"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment