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!
Crafting Interpreters: Closures
51–60 of 62 posts
Re: Crafting Interpreters: Closures
#52This 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?
Re: Crafting Interpreters: Closures
#53Author here! Happy to answer questions, accept criticism, etc. :)
Re: Crafting Interpreters: Closures
#54This 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.
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
#55Author here! Happy to answer questions, accept criticism, etc. :)
For a programming language, you'd want to use terms like "parser" and hopefully "compiler", not an unqualified "interpreter".
Re: Crafting Interpreters: Closures
#56Re: Crafting Interpreters: Closures
#57Author here! Happy to answer questions, accept criticism, etc. :)
Re: Crafting Interpreters: Closures
#58Earlier 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
Re: Crafting Interpreters: Closures
#59Earlier 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
Re: Crafting Interpreters: Closures
#60Earlier 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…