
Little Lisp interpreter - luu
https://www.recurse.com/blog/21-little-lisp-interpreter
======
tsm

        var tokenize = function(input) {
             return replace(/\(/g, ' ( ')
                   .replace(/\)/g, ' ) ')
                   .trim()
                   .split(/\s+/);
           };
    

Code like this makes me a little upset. It'll completely break on simple
cases: `(print "To close the REPL, type (quit).")` being an obvious example.

I get that it's a toy example, but all too often it slides into tricking
people that hard* problems are trivial.

* - I'm aware that tokenization has been a solved problem for decades—what I'm trying to say is that it takes quite a bit more thought than the four-line implementation suggests.

~~~
dopamean
The whole article is pretty poorly thought out. It is supposed to be an about
Lisp but doesn't even mention quote...

~~~
baddox
It is supposed to be a _little_ Lisp. At least one thing was bound to be left
out.

~~~
breadbox
Yeah, but leaving out "quote" is like leaving "if" out of C.

------
_murphys_law_
I thought the article did very well in providing an introductory resource to
students hoping to learn more about the structure of an interpreter. On the
other hand, if one wanted a nearly identical, and possibly more rigorous
approach to learning about implementing a "tiny lisp" Peter Norvig's lispy
implementation is a wonderful resource:
[http://norvig.com/lispy.html](http://norvig.com/lispy.html) ... of course any
computer scientist studying languages should also have read Mcarthy -
[http://www.cse.sc.edu/~mgv/csce330f13/micromanualLISP.pdf](http://www.cse.sc.edu/~mgv/csce330f13/micromanualLISP.pdf)

------
amelius
> (first (1 2))

How does the interpreter know that the (1 2) part is a list, and not an
application of 1 to 2?

~~~
tsm
Yes, I was incredibly surprised that there was a long article on Lisp
interpretation that didn't touch on QUOTE at all.

------
divs1210

        var tokenize = function(input) {
             return replace(/\(/g, ' ( ')
                   .replace(/\)/g, ' ) ')
                   .trim()
                   .split(/\s+/);
           };
    

shouldn't it say return input.replace( ...

------
Turing_Machine
If anyone is looking for something a little more full-featured, BiwaScheme is
a pretty decent R6RS Scheme interpreter in Javascript.

[http://www.biwascheme.org/](http://www.biwascheme.org/)

