500 Lines or Less – A Python Interpreter Written in Python
aosabook.org
aosabook.org
I can't find the sources for this.
Incomplete, no .lisp file: http://www.s2.org/~chery/projects/lisp500/
Doesn't connect: http://modeemi.cs.tut.fi/~chery/lisp500/
The most accessible source for this currently seems to be a "lisp5000" project in GitHub: https://github.com/jackpal/lisp5000
This is a derivative work whose C code has been blown up to 1600+ lines.
1: https://web.archive.org/web/20040305005602/http://modeemi.cs...
If you use that kind of deception too often, people won't take you seriously any more very quickly.
import sys
if sys.version_info.major >= 3: raw_input = input
eval(raw_input())
Or, better, just use the six package.
Wrote this for fun a while back.
Say for instance you want to implement "printf". What's stopping you from just using printf?
Initially of course, a shortcut way is to leverage as much of the host language's features as possible, then eventually, as you move further into the bootstrap process, you will want to remove reliance on the host language.
Python by no means has the monopoly in elegant implementations of itself.
This is a pretty standard stack-based virtual machine. It is not particularly elegant, nor is the underlying language designed to be particularly elegant, much less have a monopoly on such. It's designed more for clarity and practicality.
For something on the same lines which is meant to be an elegant stack-based VM, see Forth. The description at http://yosefk.com/blog/my-history-with-forth-stack-machines.... is frequently cited on HN.
It looks like a bog-standard stack VM to me. Why do you think it would be harder than this?
Now that you've had some time to stare smugly down your nose at me, my point was that it was a testament to the expressiveness of Python, and the simplicity of the VM that that VM was a reasonable thing to write in 500 lines of python. I also noted that it's sligtly less impressive in light of how Scheme was able to do something similar, but in a significantly more compact manner, as the language was more flexable, and simpler.
What makes this impressive is the medium of expression, like when an artist blows you away with a Biro drawing.
If someone wrote this in assembly in 500 lines or less (if that's even possible), it would be incredible.
This VM is meant to match Python semantics, including support for keyword arguments with defaults, lexical scope, and exceptions. Neither the original McCarthy Lisp description which qwertyuiop924 praised, nor first Lisp implementation by Russell, supported those features. The latter two features came with Lisp 1.5, whose implementations are much larger than 500 lines. http://www.softwarepreservation.org/projects/LISP .
And that's okay - a language doesn't require those features. And a language without them, like Forth, can be much more compact as a result.
Also, in case you weren't reading carefully, I also pointed to Scheme's metacircular evaluator, which implements lexical scope, continuations (of which exceptions are a subset), and can implement defaults with relatively simple extension.
In practice, some people adore Forth. Most do not. Some people adore Prolog. Most do not. Relatively more people adore Lisp than either Forth or Prolog.
Such elegance is therefore in the eye of the beholder, not some god.
Forth's elegance is how it well it matches up to most hardware. The inner loop of a Forth interpreter can be as little as a few dozen lines of assembly, and its eval not much longer.
shrug
What did you expect me to do? Argue? You made some good points. :-D
Although you do realize the god part was hyperbolic, showing an absurd maximal beauty. I'm not even very religious, it just seemed a fitting representation of such an absurd beauty. I thought that was pretty clear from the context...