Implement a programming language in 7 lines
matt.might.net
matt.might.net
The good news is that I now know where the name Y Combinator comes from. I imagine it will take me a lot longer to wrap my head around that concept, though. Truly weird haha.
https://gist.github.com/sanxiyn/523967
It was one of many from the link below. The Scheme in Racket example would've been even easier to specify concretely because it's so easy to implement read in a Scheme. Gets the C and C++ implementations more props for doing things directly. Real question is how small can those go?
Building almost nothing and using a very, high-level language definitely helps keep line count low. I wonder if we should count the runtime in these very-HLL examples. One like PreScheme, a system variant, I'd probably not count the runtime although might count the running time. :)
Want a fun project? Run this one through a Prolog compiler and create some LISP benchmarks. Then, recode it in the Mercury language, which IIRC is No 1 logic language, then see how that code performs (and looks). Should be straight-forward and enlightening for those interested in logic programming.
I do agree that the realization that it's possible to build recursive functions in the lambda calculus is mind-blowing (and far from obvious!)
Here is an example in prolog of such a meta interpreter.
interpret(true):- !.
interpret(GoalA, GoalB):- !,interpret(GoalA),interpret(GoalB).
interpret(Goal):- clause(Goal, Body), interpret(Body).