Ian Bicking: the old part of his blog

Re: Ruby python power comment 000

Umm... What?

Python 2.3.5 (#2, Nov 20 2005, 16:40:50)
>>> def f(n):
...     return lambda x: n + x
>>> inc5 = f(5)
>>> inc5(10)

In which way isn't that lexical closure?

Oh, you mean the fact . Of course it does, but it doesn't matter.that ints are immutable in Python? Or the fact that names are just that in Python: names for objects, rather than references to slots?

That doesn't have anything to do with closure. It's just the way assignments work in Python.

Lisp requires you to declare names, distinguishing assignment from binding. Python doesn't. Is Lisp's way of doing things different? Yes, it is. Is it better? I don't think so.

Why do I think so? Your example is clearly much more elegant in Lisp than it is in Python, after all. But that's not the point. A Python programmer wouldn't use functions to represent incrementors: they would use objects (ignoring the fact that, up to now, I haven't needed an accumulator in my whole life, ever). In the context of object-orientation, Python's assignment behaviour makes a lot more sense than Lisp's. Stating that Lisp deals with functions more elegantly than Python does isn't a valid point, because it doesn't matter. It's like saying that a webcam isn't well suited for typing text: true, but not very interesting.

By the way, anonymous procedures will probably disappear from Python at some point anyway. If you really think that Python converges towards Lisp, you're probably wrong.

Comment on Ruby python power comment 000
by Matthias Benkard


Oops... How did that happen?

s/. Of course it does, but it doesn't matter.//
# Matthias Benkard