

(An ((Even Better) Lisp) Interpreter (in Python)) - cgopalan
http://norvig.com/lispy2.html

======
tikhonj
If you like this sort of thing and want to learn Haskell, consider looking at
"Write Yourself a Scheme in 48 Hours"[1]. Of course, writing a Scheme
interpreter in Scheme is also classic; SICP[2] is also worth perusing.

[1]:
[http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...](http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours)

[2]: <http://mitpress.mit.edu/sicp/>

~~~
benbscholz
I have been having a lot of fun hacking together a simple Scheme interpreter
in C. This is my guide: [http://michaux.ca/articles/scheme-from-scratch-
bootstrap-v0_...](http://michaux.ca/articles/scheme-from-scratch-
bootstrap-v0_1-integers)

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.

------
tptacek
My favorite HN posting of the year so far.

There's no good reason for the label "lambda"!

~~~
thisrod
The footnote was interesting. Instead of (lambda (x) (* x x)), Smalltalk
writes [:x | x*x]. Apparently Church's original lambda notation was very close
to that.

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.

~~~
waterhouse
An alternative solution: if you're willing to allow non-ASCII characters into
your source code, then DrRacket provides a keyboard shortcut to insert a λ
character. I'll illustrate with anonymous recursion.

    
    
      > (define sum
          (λ (n)
            ((λ (f) (f f n 0))
             (λ (f n total)
               (if (zero? n)
                   total
                   (f f (- n 1) (+ n total)))))))
      > (sum 10)
      55

~~~
sneak
> if you're willing to allow non-ASCII characters into your source code

Blasphemy.

~~~
Raphael
You could use any letter, really. Perhaps l or f.

------
pjscott
A sequel to this article, where Norvig explains how to make a really minimal
(but ridiculously clear and elegant) Lisp interpreter in 90 lines of Python:

<http://norvig.com/lispy.html>

~~~
william42
From the URLs, it looks like a prequel.

~~~
webspiderus
just looks like "this" needs to be properly disambiguated :)

~~~
pjscott
Wow, that's kind of embarrassing. To eliminate ambiguity, here they are in
order:

<http://norvig.com/lispy.html>

<http://norvig.com/lispy2.html>

~~~
Raphael
2 comes after? I don't know...

------
pepijndevos
It doesn't implement real call/cc and continuations, which is what I want to
learn. Still great stuff.

~~~
spacemanaki
Lisp in Small Pieces covers call/cc and much more, and I highly recommend it.
It's deep and rich, so be warned that it may completely devour your time.

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)

------
swah
I feel like:

Interpreter in C: an implementation. Interpreter in Python: an exercise.

