3 ms·
5 minutes Lisp in Python
- mahmud 16y ago(loop (print (eval (read)))) 3-second Lisp ;-)
- judofyr 16y agoEhm? Where's the Lisp? This is just Python syntax in S-expressions.
- pepijndevos 16y agoThat is all it is indeed. So what is your definition of Lisp? Wikipedia: Lisp or LISP is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax.
- judofyr 16y agoMore from Wikipedia (which this version doesn't have): The name LISP derives from "LISt Processing". Linked lists are one of Lisp languages' major data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or even new domain-specific programming languages embedded in Lisp. It also lists the following under "Syntax and semantics": Symbolic expressions — Check Lists — Check Operators — Check Lambda expressions — Check Atoms — Check Conses and lists — Nope (not linked lists) S-expressions represent lists — Nope List-processing procedures — Check Shared structure — Nope (not linked lists) Self-evaluating forms and quoting — Nope Scope and closure — Kinda List structure of program code — Nope Evaluation and the Read-Eval-Print Loop — Nope Control structures — Nope The biggest difference which doesn't really make this a Lisp is probably that the code isn't a list, it's just a series of yield expressions. You can't really parse it as a list or manipulate it as a list. It's also missing cons/car/cdr which is sort-of the building block of Lisp languages!
- pepijndevos 16y agoOkay, point taken. Except the yield statements return plain tuples, so in fact it /is/ code as data(I just execute it as Python though). You can also have quoting by leaving of the yield, which will make it a plain old tuple.
- timruffles 16y agoGreat starting point even if it's not all the way to Lisp :) Shouldn't be too hard to add the rest - read the SICP on the meta-circular evaluator and translate http://mitpress.mit.edu/sicp/full-text/sicp/book/node76.html http://mitpress.mit.edu/sicp/full-text/sicp/book/node76.html
- pepijndevos 16y agoThat'd be nice... Write the current function to the point where I can write itself, and then add everything needed for a real Lisp. Then it wouldn't be 5 minutes anymore though.