Learn C and build your own Lisp (2014)
buildyourownlisp.com
buildyourownlisp.com
> The interpreter uses very dubious implementation decisions, and the language that is created as a side-effect makes reasoning about anything near impossible.
Personally I really like the writing style of the book and had fun following it BUT you definitely shouldn't use it as your primary source to learn about these things.You need to do you own research and figure out why some ideas presented in the book are dead-ends that should be avoided.
It is definitely NOT a useful for those who want to learn the proper way to implement a Lisp, especially a non-toy one.
Alternatives are Crafting Interpreters by Robert Nystrom and MAL (Make your own Lisp). Here is also a good-short tutorial how to write one in OCaml: https://bernsteinbear.com/blog/lisp/00_fundamentals/
Edit: Updated link to the criticism.
What makes it stand out is that it shows you how to build a compiler rather than an interpreter, and shows that it's really not that much more difficult.
There is a book-length "sequel" to this paper that goes into more detail: https://github.com/IUCompilerCourse/Essentials-of-Compilatio...
Make the compiler output some kind of bytecode in a format, which can be easily interpreted, or with the help of a Macro Assembler, very quickly transformed into machine code.
It won't win performance prices, however it is quite easy to get going.
Naturally fitting these ideas into Lisp like languages is quite straightforward.
Thanks for the book tip.
It starts with a very minimal meta-evaluator for something similar to McCarthy's original Lisp, and then explains why all the changes from Lisp 1.0 since were made. Why did language designers change things in the first place? And then it shows you how those differences are implemented. One of the first lessons is the problems with the semantics of dynamic scoping, and the implementation of dynamic vs. lexical environments. I personally worked through the book writing in SML. Despite the name and approach, it's not really a Lisp book; it's a compiler implementation book.
But for someone who just wants the most dead simple Lisp implementation possible, there's always SICP, which ends in them writing out a basic metacircular lisp intepreter on just a few blackboards, in Scheme.
Of course they skip parsing and boring details, as well as macros. But it's a good place to start.
In particular in Crafting Interpreters, there are many parts where you go back and revise the code from previous chapters as some language features/concepts are introduced in subsequent chapters (my memory of Writing an Interpreter/Compiler in Go is not that fresh).
I think it is a good sign that these books start with "int main()" (or it's equivalent). Other books I've seen start by describing functions in isolation, so they are not immediately testable, and it encourages the reader to just get the finished codebase to have something to play with.
> This book is for anyone wanting to learn C, or who has once wondered how to build their own programming language.
which I interpret as having "design a language" as another goal. Arguably the book succeeds at building a programming language, but it mangles the theory in unhelpful ways, e.g. lexical scoping isn't a static analysis per chapter 16, nor is parsing the consumption of an abstract syntax tree per chapter 10.
(Just a polite other viewpoint)
that would be a car crash!
(edited cos it came across a bit horrible unintentionally)
It starts with: >> First off: God help you if you are going to write your first interpreter in C of all things.
How can anybody take this seriously.
Good references for building a Lisp are "Lisp in small pieces" and Nils Holm's "LISP from nothing".
If one wants to learn specifically how Java works, then maybe a book on compilers would be better?
Note that Lisp in Lisp (SICP) works well because Lisp itself is very simple and just the essentials. It's just one chapter in SICP.
JikesRVM, MaximeVM and now GraalVM.
I've been meaning to pick it back up, but was considering going through Crafting Interpreters first (and started reading it but since I don't know Java I spent more time trying to figure out a good setup with Java and Emacs).
How is Nils Holm's "LISP from nothing?" I discovered it a while ago, but probably judged it by its cover (and the typesetting).
Any other recs in the PL/compilers world would be appreciated. I'm probably the only person that did not like EOPL. I bought the 3rd edition, went back to the 2nd edition, and at some point early on the eval did not work. Which is a shame since I enjoyed Friedman's Little/Seasoned Schemer and Scheme and the Art of Programming
That is in my opinion just completely unconstructive hate that I would not take serious as criticism. It doesn't give any concrete things that could be improved and instead just gives some vague statement about the whole site being generally bad.
My dad was a high school math teacher who became a COBOL programmer by accident in the early 1980s because a large local IT company put out an ad saying they’ll hire anyone with a college degree. A couple of years later, when I was eight, I was writing terrible BASIC programs and asked him if it’s possible to invent a new programming language. He showed me how to write an interpreter in BASIC for a custom language. It wasn’t useful for anything and it certainly had no LISP-like elegance, but it was a revelation to me that everything that happens on the computer was defined by people, and I can be one of those people even if I’m an eight-year-old in the middle of nowhere.
Never forget.
Chapter 22, Scheme: An Uncommon Lisp
https://norvig.github.io/paip-lisp/#/chapter22
Chapter 23, Compiling Lisp
BYOL is nice because it’s short and quick (you can power through it in a weekend) and gets you some momentum if you’ve never written a basic language.
Move on to something like Crafting Interpreters which is a well thought out book but definitely more of a marathon than a sprint.
They did build lisp from a intermediate assembly language, then a bootstrap C compiler to compile tinycc then gcc 4.7.4, then gcc (the last iso C++98 one), then the last gcc (is c++11).
Yep, moving gcc to c++ is one of the biggest mistakes in open source software, ever.
Regarding FOSS, C++ is also a UNIX child, born on the same offices.