6 ms·
I'm a bit put off by your combination of praise and dismissiveness when I think neither are warranted. This is a pretty standard stack-based virtual machine. I
by dalke 10y ago
I'm a bit put off by your combination of praise and dismissiveness when I think neither are warranted.
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.html http://yosefk.com/blog/my-history-with-forth-stack-machines.... is frequently cited on HN.
- qwertyuiop924 10y agoI meant it was impressive that it was so simple to implement the python VM in itself, but becomes less impressive when compared to the simplicity and elegance with which you can do similar feats in other languages. I find that point valid.
- dalke 10y agoWhile I don't see what it is that you, who has looked into how other languages are implemented, finds impressive. It looks like a bog-standard stack VM to me. Why do you think it would be harder than this?
- qwertyuiop924 10y agoIt's impressive that it could fit into 500 lines of Python.
- dalke 10y agoHave you looked into many other stack VM implementations? 500 lines of Python seems entirely reasonable.
- qwertyuiop924 10y agoNo, no I haven't. I know a bit about programming languages, not massive amounts. 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.
- dalke 10y agoI am smug for pointing out that I dislike your original smugness. Understood.
- qwertyuiop924 10y agoI wasn't trying to be smug. Clearly, I came across that way.
- jwdunne 10y agoLisp will always be a special case. It's too powerful to give other languages a running. It's not quite the same when the language makes it ridiculously easy to build new languages. 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.
- dalke 10y agoI have a different observation. 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 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.
- nickpsecurity 10y agoI was curious so looked up McCarthy's paper. Appendix B has code and pseudo code for minimal interpreter. Takes one page. Primitives are easy to code, too. It would surpise me if that took much larger than 500loc to implement.
- qwertyuiop924 10y agoLexical scope, in particular, is very easy to implement. Call/cc or exceptions are a bit tougher, but it can be done. And all defaults take is a bit of extension to the lambda. In fact, defaults can be added atop the language with a macros, as can keyword arguments. Macro expanders are a bit harder to write than the functionality itself, however. Especially if you want a good one.
- qwertyuiop924 10y agoI wasn't intending to praise it, just show that other languages did similar things more elegantly. 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.