News for hackers. Stuff that matters.
Re:New C++ features – lambdas by AnimalMuppet on Wednesday October 28, 2015 @06:10PM (#10467789)
Thanks. So if I understand all this correctly, in Lisp and Scheme and so on, you can do this because the created function can maintain a reference to C's local variable that is valid after C terminates, whereas C++ can't do that. This is because in Lisp, the new function holds a reference to the value, and that value will be good until garbage collected, and it won't be garbage collected while there's a valid reference to it. Whereas in C++, the local variable is just a stack offset, and when C terminates, that is no longer valid.

That is, it seems to me that the essential feature that makes this work is garbage collection (and that all local variables are references to values that will live until garbage collection). Do I have that right?

Re:New C++ features – lambdas by xigency on Wednesday October 28, 2015 @10:28PM (#10468845)
Yes, that is exactly the case and you've understood the issue perfectly. I wouldn't go so far as to say first-class functions must have a garbage collector to work, but I would say that they are so dependent that this would really be a bold area of computer science research.