4 ms·
I used McCarthy definition of LISP in LISP to implement my first LISP Interpreter in C++. I just written in C++ following functions: car, cdr, cons, cond. Then
by nivertech 16y ago
I used McCarthy definition of LISP in LISP to implement my first LISP Interpreter in C++. I just written in C++ following functions: car, cdr, cons, cond. Then I translated line by line eval and apply function into C++.
All the rest functions were implemented in LISP itself.
EDIT: I also implemented simple mark-and-sweep garbage collector - otherwise you will be running out of memory pretty quick.
- singular 16y agoAwesome. Do you have that in a code repo you can point us to? :-)
- nivertech 16y agoUnfortunately not. It was my diploma project in 1994. It was called: "LISP Interpreter with IDE for Windows". It was implemented using Borland C++. And LISP interpreter was just a small part of the project. The rest was building Borland C++ inspired IDE for Windows, for which I also implemented my own GUI C++ class library on top of Win32 API. I still have code printed in the hardcopy (which was requirement of my college), but floppy disks with the source code didn't survived ;)
- jacquesm 16y agoScanner + OCR ?
- jsn 16y agoI probably used a somewhat similar approach to Scheme, here's my just-for-fun implementations: http://github.com/jsn/sillyscheme http://github.com/jsn/sillyscheme . Eval is not that straightforward, though -- you have to implement tail-call elimination and call-with-current-continuation for scheme.
- gjm11 16y agoThis is also how the first ever Lisp implementation was made. Supposedly, McCarthy had never intended his definitions of EVAL and APPLY -- not in this "micro-manual", but in his original Lisp paper -- to be actually implemented. Some guy called S R Russell (I imagine him as a graduate student but have never checked) looked at the paper and thought "wait, we can type this code in, write a bit of supporting code, and get an actual Lisp implementation", and so history was made.
- JeanPierre 16y agoYeah, Steve Russell was a graduate student. Also, this is what McCarthy said during an interview: Steve Russell said, look, why don't I program this eval..., and I said to him, ho, ho, you're confusing theory with practice, this eval is intended for reading, not for computing. But he went ahead and did it. That is, he compiled the eval in my paper into [IBM] 704 machine code, fixing bugs, and then advertised this as a Lisp interpreter, which it certainly was. So at that point Lisp had essentially the form that it has today.... (Source: http://www.paulgraham.com/icad.html http://www.paulgraham.com/icad.html - not really surprising)
- gruseom 16y agoNorvig has the best line about this: "So the first Lisp interpreter was the result of a programmer ignoring his boss's advice." (PAIP p. 777)
- gruseom 16y agoIt gets even better. Steve Russell went on to write the very first video game (http://en.wikipedia.org/wiki/Spacewar! http://en.wikipedia.org/wiki/Spacewar!). I'd really like to know what else he did, and what he's doing now. The guy is a hero.
- jacquesm 16y agoSuper! It's been my dream for over a year now to grok lisp sufficiently that I can do that. Still not there yet, but not giving up. I'm a slow learner. People like Patrick Collison impress the hell out of me for doing such stuff apparently effortless.