19 comments

[ 2.9 ms ] story [ 56.6 ms ] thread
Cool. I have been working through the lessons in Nathan's University (http://nathansuniversity.com/) which take you writing a Lisp interpreter (though admittedly with less rigor than this project) in Javascript.

Definitely recommended if you want a starting point for something similar and don't know where to begin.

I found one bug: you cannot create a zero argument lambda, e.g. (lambda () 42) will not work. You could also benefit from separate `let' construct, because simulating them with lambdas is a bit painful.

Apart from that, it works quite nicely (I was positively surprised you went for lexical scoping), but without macros, you can hardly say it's a Lisp, it's a language with Lispy syntax.

Yep, this is still very much a work in progress. Metacircular eval and macros are up next.
> You could also benefit from separate `let' construct, because simulating them with lambdas is a bit painful.

> without macros, you can hardly say it's a Lisp, it's a language with Lispy syntax.

These two things go together: many lisps have let as a macro that uses lambda internally.

> I was positively surprised you went for lexical scoping

Indeed; that makes for a much more usable language.

nice job! I like how clean the source is, it would be really easy to extend or use as a base for writing ones own interpreter.
Hi everyone, original author here. Thanks for all the feedback! My friend posted this before it was really ready for public consumption.

My goal here was to learn how Lisp works at a really low level. I'm planning to add the features you would expect from a Lisp (e.g. macros) very soon.

That's a very nice beginning, I love being able to interpret Lisp in the browser!

Your interpreter would be even more awesome if its interface was a file buffer instead of a toplevel. But so far, great work!

Coincidentally I just started working on one last weekend too. http://github.com/garyb/fiction

It's more Scheme influenced (but not at all RnRS compliant) and as of about half an hour ago has working define-syntax/syntax-rules style macros.

The code isn't as nice though ;). I just wanted to get it working so I could rewrite it in itself.

Why does this happen:

    (def a 3)
    3

    a
    null
a should be 3, not null.
Same thing happens if you just try to pass it a bare 3. I'm thinking nothing gets evaluated without parens.
Thank you for implementing command history :).

There is a slight bug though. Since the position gets updated after the position is calculated, the displayed value is out of sync.

So entering

1

2

3

And then typing: UP (3), UP (2), DOWN (1)

Displays 1, rather than 3.

Consider a different name -- "Cells" is the name of a cool Common Lisp library by a ... let's say notorious ... Lisp programmer.

http://common-lisp.net/project/cells/

It is also the name of at least two programming languages already.
What's notorious about Kenny Tilton?
He was a regular poster on comp.lang.lisp, and one of the contributors there described him thusly:

"Ken Tilton is an aquired taste - if you can ignore his inflammatory remarks his advice is usually good. When I first saw some (most!) of his posts I initially thought WTF! but think of him as someone with Tourettes Syndrome and just look at what he is saying not how he is saying it!"

There's a couple of fortune cookie files of quotes from him (collected by someone else, but you can find them on his blog), they do make for funny reading, but you can see how some of this would sting if the remarks were directed at you: http://smuglispweeny.blogspot.co.uk/2010/08/fortune-cookie-f...

Gotta shout out to my own Lisp-in-JavaScript interpreter from long, long ago: http://joeganley.com/code/jslisp.html ... far less complete than this, but perhaps interesting to someone for archeological reasons or something.