
How to Write a Lisp Interpreter in Python (2010) - xorbox
http://norvig.com/lispy.html
======
marcpaq
I'm always impressed how the magic of interpreters and compilers can be
explained so succinctly.

Inspired by Jonesforth, I wrote a complete Lisp interpreter in a single ARM
assembly file:
[https://github.com/marcpaq/arpilisp](https://github.com/marcpaq/arpilisp)

~~~
cagmz
How long did it take you? The documentation is A+ (it reminds me of this
compiler: [https://github.com/thejameskyle/the-super-tiny-
compiler](https://github.com/thejameskyle/the-super-tiny-compiler) ).

~~~
marcpaq
I estimate it took 60-70 hours, of which 2/3 of that was for the
documentation.

Thanks for the compliment and the link to TSTC. I'll add it to my personal
list.

------
rcarmo
Obligatory link to today's best solution, using the Python AST and running
straight off bytecode: [http://hylang.org](http://hylang.org)

~~~
pryelluw
I've always found Hy interesting, but cannot picture anyone using it in
production. Are there any real live examples?

~~~
rcarmo
The maintainers quoted having a few customers using it, but here's my stuff:
[http://github.com/rcarmo/sushy](http://github.com/rcarmo/sushy)

~~~
pryelluw
That code is more readable than I expected. :) May you share more about the
experience of using it? Do you keep a blog?

~~~
rcarmo
Erm. My blog runs on it, it's the demo site :)

~~~
pryelluw
Well, ok. :)

I tweeted the repo link to the HyLang account.

------
jacquesm
Original HN Submission + discussion here:

[https://news.ycombinator.com/item?id=1745322](https://news.ycombinator.com/item?id=1745322)

(and many re-submissions after that)

Follow up:

[https://news.ycombinator.com/item?id=1746916](https://news.ycombinator.com/item?id=1746916)

------
dancek
For anyone wanting to try something similar yourself, I highly recommend MAL.
It's a Lisp dialect designed to be a learning tool: there's a nice guide for
implementing the interpreter. It doesn't take much away from the learning, but
it really lessens the possible frustration a lot.
[https://github.com/kanaka/mal/blob/master/process/guide.md](https://github.com/kanaka/mal/blob/master/process/guide.md)

Just in case anyone is interested, here's my implementation in Python 3.5+.
I'm guessing it took me about 15 hours to write.
[https://github.com/dancek/mal/tree/python3-dancek/python3-da...](https://github.com/dancek/mal/tree/python3-dancek/python3-dancek)

Of course, Peter Norvig's followup to the linked article may also interest
anyone who read this far:
[http://norvig.com/lispy2.html](http://norvig.com/lispy2.html)

------
atobe
Is LISP still relevant? ;-)

I'm curious whether folks think the ideas of LISP are still resonant and
powerful in the startup world and wider industry.

This is different from the question of inspiration. Yes, I admire.

Does PG, for instance, still think that startups can have 'secret' technical
advantages and use strategies like 'running upstairs', i.e. choosing to do
hard things as a competitive advantage.

By ideas of LISP I mean things like programs-as-data and a small kernel from
which the system is bootstrapped.

------
krylon
He he, I wrote a (primitive) Lisp interpreter in Python once. It was crappy
and really slow, but it had lexical scoping and a (naive) macro system. Fun
times... ;-)

------
whistlerbrk
Along the same lines may I say buildyourownlisp.com somehow manages to be a
great intro text to C as well as lisp. Highly recommended

------
keithgabryelski
Here is my version of a lisp interpreter in python:

[https://github.com/keithgabryelski/plisp](https://github.com/keithgabryelski/plisp)

it's not meant to be pythonic -- it's meant to readable and organized

my inspiration was Interpreting LISP by Gary D. Knott written in 1997 (the pdf
of it is included in the repository)

------
rosstex
This is currently the final project of CS61A, the introductory CS course
taught at UC Berkeley.

[https://inst.eecs.berkeley.edu/~cs61a/fa14/proj/scheme/](https://inst.eecs.berkeley.edu/~cs61a/fa14/proj/scheme/)
(no link for the current semester is up yet)

------
ojno
Surely something more like

(how (in 'python (write (interpreter 'lisp))

:-P

~~~
pavelludiq
More like:

    
    
      (howp (write (interpreter :of :lisp
                                :in :python))))

~~~
mmarx
> howp

“how?” is not a predicate (i.e. something that returns a Boolean value), so it
wouldn't be named howp.

~~~
qubex
Somebody read the Jargon File...

------
erikb
This is from 2010. Please mark in the title.

