3 ms·
var tokenize = function(input) { return replace(/\(/g, ' ( ') .replace(/\)/g, ' ) ') .trim() .split(/\s+/)
by tsm 11y ago
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 11y agoThe whole article is pretty poorly thought out. It is supposed to be an about Lisp but doesn't even mention quote...