Live data from Hacker News

Crafting Interpreters: Closures

craftinginterpreters.com

51–60 of 62 posts

Re: Crafting Interpreters: Closures

#51
post #6

The implementation described here is inspired by Lua. Even if you already know what a closure is, it might still be a worthwile read, since it probably implements them very differently from what you are thinking! Instead of always heap-allocating variables that are used by closures, it starts by stack-allocating them and only moves them to the heap if the closure outlives its parent function. In order for this to wor…

Another approach is to do the opposite - always store all local variables in the heap, and rely on scalar replacement of aggregates to put them back onto the stack where possible. This is what I do in my Ruby interpreter. That’s definitely not compatible with a single-pass though!

A third option that can still be single pass is the Smalltalk way, where the stack frames themselves are first-class objects: the closures then keep a reference to the stack frame and the GC won't collect any live stack frames, which will contain closed-over variables.

Re: Crafting Interpreters: Closures

#52
post #3
post #2

This is one of my favorite books(-in-progress) to follow along with. If you've ever even had a passing curiosity in how interpreters work, I highly recommend checking it out from the beginning: http://craftinginterpreters.com/welcome.html The writing is charming and approachable, while still packed with an impressive amount of knowledge.

Any more gems like this you would recommend?

Crenshaw's "Let's Build a Compiler" is also a very lucid read: https://compilers.iecc.com/crenshaw/

Re: Crafting Interpreters: Closures

#54
post #2

This is one of my favorite books(-in-progress) to follow along with. If you've ever even had a passing curiosity in how interpreters work, I highly recommend checking it out from the beginning: http://craftinginterpreters.com/welcome.html The writing is charming and approachable, while still packed with an impressive amount of knowledge.

>"The writing is charming and approachable, while still packed with an impressive amount of knowledge."

Agreed. I came here to say the same. "Charming" and "approachable" sums up the writing style nicely. I'm always excited when there's a new chapter.

Re: Crafting Interpreters: Closures

#55

Author here! Happy to answer questions, accept criticism, etc. :)

A title like "Crafting Interpreters" on this gets my hopes up. I expect something about building an emulator like Qemu, MAME, or Xenia.

For a programming language, you'd want to use terms like "parser" and hopefully "compiler", not an unqualified "interpreter".

Re: Crafting Interpreters: Closures

#56
Are there any advantages or disadvantages with learning how to build an interpreter versus learning how to build a compiler? I'm asking since I will be taking a compiler class in college soon and this book looks really interesting to me. Usually I see school curriculums have a class on compilers instead of interpreters.

Re: Crafting Interpreters: Closures

#58

Earlier quoted context omitted.

> The writing is charming and approachable, while still packed with an impressive amount of knowledge. It's actually the best technical writing I have ever seen, and I have read a lot. He can explain a complex thing really easy, and bring it very personally, as if he's a good, relaxed and funny friend explaining things.

Thank you! :D

No, thank you for writing these! I haven't read your book on interpreters yet, but your game programming patterns book helped me a ton when I was building my own game engine.

Re: Crafting Interpreters: Closures

#59

Earlier quoted context omitted.

> The writing is charming and approachable, while still packed with an impressive amount of knowledge. It's actually the best technical writing I have ever seen, and I have read a lot. He can explain a complex thing really easy, and bring it very personally, as if he's a good, relaxed and funny friend explaining things.

Then you should check his book on game programming patterns: http://gameprogrammingpatterns.com/index.html

Haha, I'm in the book of game programming patterns :D (deWiTTERS game loop)

Re: Crafting Interpreters: Closures

#60

Earlier quoted context omitted.

From what I have read about Wirth his way of thinking is the computer science equivalent of Bauhaus minimalism. Which oddly enough doesn't appeal to me in the design of everyday things all that much (I can definitely respect it though), but feels very fitting for computer science.

Wirth's minimalism is, IMO, driven by some semi- or full understanding of formal semantics, wherein simplicity is essential to correctness in implementation of the language (as the language designer), and essential to the correct use of the language (as a programmer). This is my opinion formed from what I read so beware. C.A.R. Hoare has excellent stuff to say on this and hardware design - here's his 1982 turing awar…

Thank you for both that comment and that link!
Post reply on HN