(An ((Even Better) Lisp) Interpreter (in Python))
norvig.com
norvig.com
[1]: http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...
The implementation of an interpreter has always interested me, but I never thought it was within my reach as a weekend project. Norvig's original lis.py post made me look around for other implementations. This follow-up is a real treat.
There's no good reason for the label "lambda"!
This helps more than you'd think. For example, (if condition (lambda () foo) (lambda () bar)) is too verbose, but (if condition [foo] [bar]) is fine. Simplifying lambda gives you lazy evaluation, and then you don't need syntax for conditionals.
> (define sum
(λ (n)
((λ (f) (f f n 0))
(λ (f n total)
(if (zero? n)
total
(f f (- n 1) (+ n total)))))))
> (sum 10)
55Blasphemy.
Gamma function, gamma constant, gamma correction, gamma radiation, gamma distribution, and there went an hour I could have been wasting on today's best catpictures.
Another look at call/cc is in Marc Feeley's 90 Minute Scheme to C Compiler:
http://news.ycombinator.com/item?id=2633841 (submission that incudes a link to slides and video)
Interpreter in C: an implementation. Interpreter in Python: an exercise.