Live data from Hacker News

Show HN: Crafting Interpreters – A handbook for making programming languages

craftinginterpreters.com

21–30 of 77 posts

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#21
post #6

Another great-looking book on making dynamic languages. There's been some good ones recently, and this one looks like another good one covering how to make a basic, interpreted language. Some of us have written 1 or 2 dynamic, interpreted languages, feel pretty comfortable with those concepts, and are interested in transiting to more advanced, static type systems and writing a good type checker. Anyone up for writing…

There's nothing more "advanced" about statically typed languages. Static typing and type inference are straightforward and can make implementation details simpler than dynamic languages (because you're greatly reducing or removing the unknowns you have to deal with at runtime). This is assuming you're making a batch-style compiler, as most implementors do, and not an interactive system.

If you're focused on benchmark numbers, dynamically typed languages are much more challenging to squeeze performance out of better code generation.

You can also add static type inference and consistency checking to a dynamic language, and indeed some systems do in the name of better

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#22
post #5

Thank you so much for the book, please, continue! I am currently working on Scheme R5RS implementation in Java. It is a hobby project, but I'm really enjoying it. It is somewhat enlightening. Look forward to reading the Optimization chapter: I couldn't find much useful and practical info on that. I think it is quite easy to implement your interpreter, but it is really difficult (at least for me) to make it fast. Can…

> Thank you so much for the book, please, continue!

I will!

> Look forward to reading the Optimization chapter: I couldn't find much useful and practical info on that.

There's not too much depth in that particular chapter. The whole second part is really about implementing an interpreter (fairly) efficiently in C. As you probably know, you have to think about performance at every level—your object model, bytecode format, hash table implementation, etc.

If you'd like a sneak peek, the code for the entire book is actually done already (!). You can see which snippets go into each chapter cloning the repo[1] then running:

    make chapters
    make c_chapters
    make diffs
Then take a look in build/diffs.

There are a ton of optimization tricks that are specific to Scheme and Lisps and a lot of literature behind them. Macros and eval make it a lot harder. It's pretty dense, but I liked "Lisp in Small Pieces" a lot.

[1]: https://github.com/munificent/craftinginterpreters

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#23
post #14
post #5

Thank you so much for the book, please, continue! I am currently working on Scheme R5RS implementation in Java. It is a hobby project, but I'm really enjoying it. It is somewhat enlightening. Look forward to reading the Optimization chapter: I couldn't find much useful and practical info on that. I think it is quite easy to implement your interpreter, but it is really difficult (at least for me) to make it fast. Can…

For making an efficient Scheme implementation: most everything written by R. Kent Dybvig or his students. I'd start with his PHd thesis (Three Implementation Models for Scheme, specifically the stack-based part). http://www.cs.indiana.edu/~dyb/ (See also Lua's upvalues for a way to optimize closure variable access that's a bit simpler than his display closures).

> See also Lua's upvalues for a way to optimize closure variable access

Yes! In fact, that's how the C version of the interpreter in my book implements closures. It's pretty brilliant. <3 those Lua folks.

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#24

Looking forward to the chapters about the C interpreter. Meanwhile, it looks like both interpreters are available to study now in the Git repo. [1] [1]: https://github.com/munificent/craftinginterpreters

Yes! The code for the whole book is done already and sliced into chapters. I had to do that first before I started putting things online. I didn't want to paint myself into a corner by having something in an earlier chapter that ended up not making sense later.

So the code is all done, and now "all" that's left to do is write and edit all of the prose. Which, of course, is really the hardest part by far.

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#25
post #6

Another great-looking book on making dynamic languages. There's been some good ones recently, and this one looks like another good one covering how to make a basic, interpreted language. Some of us have written 1 or 2 dynamic, interpreted languages, feel pretty comfortable with those concepts, and are interested in transiting to more advanced, static type systems and writing a good type checker. Anyone up for writing…

Writing a type-checker is fun and pretty interesting. For that, I recommend you get acquainted with formal semantics and judgements (that's just the language for describing type-systems). You'll probably be interested in then looking up

  * simply typed lambda calculus
  * Hindley-Milner type inference
  * bidirectional typing
After that, there are all sorts of cool things like linear/affine types, system F, dependent types, etc. which can be picked up.

All of this (except maybe the first part) is easily learnable either from Wikipedia, the original papers, or recent tutorials.

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#26
post #6

Another great-looking book on making dynamic languages. There's been some good ones recently, and this one looks like another good one covering how to make a basic, interpreted language. Some of us have written 1 or 2 dynamic, interpreted languages, feel pretty comfortable with those concepts, and are interested in transiting to more advanced, static type systems and writing a good type checker. Anyone up for writing…

I did think about trying to sneak a type checker in here too, but it's just too much for a first book on languages and interpreters.

If you're looking for a book on statically typed functional languages, I think Appel's book[1] is canon. From what I've heard, the C and Java ones aren't very great. It's worth learning enough ML to get through that version because ML is clearly the language Appel thinks in.

[1]: http://www.cs.princeton.edu/~appel/modern/

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#27
post #6

Another great-looking book on making dynamic languages. There's been some good ones recently, and this one looks like another good one covering how to make a basic, interpreted language. Some of us have written 1 or 2 dynamic, interpreted languages, feel pretty comfortable with those concepts, and are interested in transiting to more advanced, static type systems and writing a good type checker. Anyone up for writing…

Writing a type-checker is fun and pretty interesting. For that, I recommend you get acquainted with formal semantics and judgements (that's just the language for describing type-systems). You'll probably be interested in then looking up * simply typed lambda calculus * Hindley-Milner type inference * bidirectional typing After that, there are all sorts of cool things like linear/affine types, system F, dependent type…

Notes only tell half the story, but these are good notes on the first two topics.

https://www.cs.cornell.edu/courses/cs4110/2016fa/schedule.ht...

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#28
post #21
post #6

Another great-looking book on making dynamic languages. There's been some good ones recently, and this one looks like another good one covering how to make a basic, interpreted language. Some of us have written 1 or 2 dynamic, interpreted languages, feel pretty comfortable with those concepts, and are interested in transiting to more advanced, static type systems and writing a good type checker. Anyone up for writing…

There's nothing more "advanced" about statically typed languages. Static typing and type inference are straightforward and can make implementation details simpler than dynamic languages (because you're greatly reducing or removing the unknowns you have to deal with at runtime). This is assuming you're making a batch-style compiler, as most implementors do, and not an interactive system. If you're focused on benchmark…

I meant "advanced static-typing" (e.g, like System F, which is advanced to someone learning PL). Not that it was more advanced, although I think in fact it is from a learner's point of view. It's incredibly simple to throw together a Scheme, or even a more complex interpreted dynamic language.

Add in a static typing, type inferencing, and type checking, and that all becomes much more complicated, at least from this learner's point of view. From how highly upvoted my comment is, I suspect I'm far from being alone here. Learning, understanding, and implementing Hindley-Milner by itself was harder for me than learning how to put together a basic interpreter for a simple scheme. And I think a big part of that is the dearth of learning materials for things like Hindley-Milner and related concepts, whereas there are 100 books and tutorials on how to implement a Scheme interpreter in language X.

Finally, if you're talking about language performance, then yes clearly it's much harder to squeeze performance out of dynamic languages. But I'm talking about learning exercises here, not production programming languages.

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#29

Looking forward to the chapters about the C interpreter. Meanwhile, it looks like both interpreters are available to study now in the Git repo. [1] [1]: https://github.com/munificent/craftinginterpreters

Me too; I'm looking for a way to learn more about building data-structures in C.

Re: Show HN: Crafting Interpreters – A handbook for making programming languages

#30

Earlier quoted context omitted.

Writing a type-checker is fun and pretty interesting. For that, I recommend you get acquainted with formal semantics and judgements (that's just the language for describing type-systems). You'll probably be interested in then looking up * simply typed lambda calculus * Hindley-Milner type inference * bidirectional typing After that, there are all sorts of cool things like linear/affine types, system F, dependent type…

Notes only tell half the story, but these are good notes on the first two topics. https://www.cs.cornell.edu/courses/cs4110/2016fa/schedule.ht...

Those are very good notes that have come up frequently in my Google searches.
Post reply on HN