Last active
October 27, 2017 18:04
-
-
Save markomanninen/d0549e1ea5dd052b48487f9cc2add69e to your computer and use it in GitHub Desktop.
Lambda Calculus Interpreter
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
(eval-and-compile(defmacro D[&rest e]`(defn ~@e))(D €[a b](.extend a b)a)(D §[a](.reverse a)a)(D ¤[a](first a))(D ?[e](instance? F e))(D £[e](if(coll? e)(if(?(¤ e))(£(apply(¤ e)(rest e)))(if(? e)e(do(def x(list(map £ e)))(if(?(¤ x))(£ x)x))))e))(D $[a b c](if(coll? c)(if(? c)(if(=(¤ c)a)c(F[(¤ c)($ a b(second c))]))((type c)(genexpr($ a b d)[d c])))(if(= a c)b c)))(defclass V[HySymbol](D --call--[self &rest v](€[self]v)))(defclass F[HyExpression](D --call--[self a &rest b](def e(£($(¤ self)a(second self))))(if b(def e(apply e b)))e)))(defmacro L[&rest e](reduce(fn[y x]`((fn[](def ~x(V(gensym'~x)))(F[~x ~y]))))(§(list e)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lambda calculus interpreter in Hy, 630 chars (648 bytes) minified. Supports multiary argument notation and multiple parameter passing. No need for dot because the last element of the function is taken as the body of the function.
Calculating the fourth triangular number by Lambda calculus using ycombinator:
should yield: 10