4 ms·
Nothing. I never said that Python doesn't provide closures. I just pointed out that Mr. Prescod did not give an example for those, even though he writes about c
by lispm 16y ago
Nothing. I never said that Python doesn't provide closures. I just pointed out that Mr. Prescod did not give an example for those, even though he writes about closures. He really was talking about lexical scope. He did not demonstrate closures for my satisfaction, he didn't demonstrate them at all.
This makes me guess that Mr. Prescod never understood what a closure is, since he failed to give any example. That one can set closed over variables in Lisp is a useful feature. He demonstrates that Python 2 can't set a variable of an enclosing scope and claims that he does not need that. Maybe if he were really using closures, he would have found it useful.
- btilly 16y agoBut he did give an example. In his example, bar is a function object that is a closure. He just didn't make it do anything that would demonstrate it had to be a closure. As for Pascal, you need to look again. From the beginning Pascal had the ability to pass functions and procedures as parameters to other functions and procedures. If those functions and procedures are defined in an inner scope, they will carry the original lexical scope, and are in fact full closures. OK, they are clunky to use, but they work. Skip to the end of the section starting at http://en.wikipedia.org/wiki/Comparison_of_Pascal_and_C#Functions.2Fprocedures http://en.wikipedia.org/wiki/Comparison_of_Pascal_and_C#Func... to see the necessary syntax demonstrated. Don't quote me on this, but I believe that Pascal was actually the very first language with full closures. All of the necessary pieces are in ALGOL-68, but I think that Pascal was implemented first and so wins. Incidentally Sussman claims that he got the idea of lexical scope for Scheme from studying ALGOL. Of course Scheme realized the possibilities of the construct as no language before it had, and a lot of credit is due for that. But you shouldn't lightly dismiss the contributions to Lisp from languages out of the Lisp family.
- lispm 16y agoNo, bar is not a closure. It is basically just a local procedure. The original Pascal did not have full closures. Functions did only exist as long as their surrounding function was called. They could not be returned from functions. Pascal lacked also the necessary Garbage Collection. Pascal had lexical scope, but not full closures. All you could do was pass functions to other functions. But that's trivial, since each time one passed function X, it gets its active environment, which always is on the stack. There was no way to have closures, where functions have their own set of variable bindings, even when the surrounding function is no longer active. Being able to pass a function downwards is not sufficient to require full closures. Basically the same applies for Algol. Functions can't be returned and are not first class objects. What Algol contributed to the evolution of Lisp was lexical scope, but not closures. Also note that it was not Scheme that introduced closures in Lisp. That's what I fear, many people think they know what a closure is, but in reality there is a lot of confusion.
- omaranto 16y ago> No, bar is not a closure. It is basically just a local procedure. bar is a variable whose value is a closure. In python, defining a named function just creates a variable whose value is a closure.
- btilly 16y agoYou are right in your description of the limitations of Pascal. As for your claim that it was not Scheme that introduced closures to Lisp, I'd like to hear more about that. I've run across the claim that Scheme was from a number of sources, including http://en.wikipedia.org/wiki/Closure_%28computer_science%29 http://en.wikipedia.org/wiki/Closure_%28computer_science%29, and I haven't heard of any other prior art.
- lispm 16y agoIt lists the paper of Joel Moses. Look for 'funarg problem'.