News for hackers. Stuff that matters.
Re:Adventures of an imperative programmer in the land of fp by silentbicycle on Friday August 27, 2010 @11:59PM (#1641133)
Yes - everything will act as if that stack frame was heap-allocated and still exists* . You can modify the value(s), define multiple functions sharing the same variable bindings, etc. A lot of common language features (such as conventional objects) can be implemented as syntactic sugar on top of closures. (Same with continuations.)

* Compilers/interpreters are free to do optimizations that won't affect results, like only heap-allocating the closures that escape their scope.

Re:Adventures of an imperative programmer in the land of fp by jacquesm on Saturday August 28, 2010 @11:10AM (#1641805)
Thanks!
Re:Adventures of an imperative programmer in the land of fp by silentbicycle on Saturday August 28, 2010 @01:11PM (#1641982)
When I'm struggling with what a programming concept means, I find it helpful to try implementing it in a toy interpreter. Efficiency is irrelevant, it just needs to model the concept correctly.

Many concepts really aren't that complicated if you're not worried about optimization, and getting to a working model tends to shake out the aspects you don't completely understand. (This is also why books have exercises.)

Re:Adventures of an imperative programmer in the land of fp by jacquesm on Saturday August 28, 2010 @04:04PM (#1642307)
> When I'm struggling with what a programming concept means, I find it helpful to try implementing it in a toy interpreter.

That's my 'I have understood' benchmark. If I can re-implement something without any reference to outside sources.

My goal is to write a little lisp or scheme from the ground up from nothing but the lambda calculus and some bits & pieces. It'll be slow as molasses but it will help me to really grok it.

That's why I've been reading up on all this stuff over the past year or so. After that I think I'm ready for something more involved, like clojure. I realize that this is not a very efficient way of learning but in the long run it tends to pay off. Knowing what goes on under the hood is an advantage.

Re:Adventures of an imperative programmer in the land of fp by silentbicycle on Sunday August 29, 2010 @08:23AM (#1643690)
Yeah, it seems like the long way around, but it really adds up over the years!

You'll probably want to get Quinniec's _Lisp in Small Pieces_, if you don't have it already. It covers several aspects of implementing Lisp interpreters and compilers, the lambda calculus, a bit on semantics, etc. (It mostly focuses on Scheme.)