Who's minister of propaganda this week?

Amit Patel amitp at Xenon.Stanford.EDU
Sun Mar 18 18:13:21 CET 2001

 Darren New  <dnew at san.rr.com> wrote:
| Phlip wrote:
| > Ruby trumps Python in the simple matter of
| > closures (imagine my shock when I discovered Python didn't have them). 
| Can someone summarize the important difference between closures and object
| instances? Other than convenience, I mean, it would seem that something like
| class yadda:
|   def __init__(self, a, b):
|     self.a = a ; self.b = b
|   def __call__(self, x, y):
|     return (self.a + x * self.b * y)
| would seem to be quite a lot like a closure with a and b bound and x and y
| free?

Don't underestimate convenience.  :-) If you had to declare each
string value in your program as a class like the above, it would make
strings less useful in a practical sense although they'd still be
equivalent in a theoretical sense.  C++ suffers from this when it
comes to container types -- building a list or array takes a lot more
syntax than just "[1, 2, 3]" so people use them less casually.
Function objects in C++ are even worse, although perhaps the "Lambda
library" (http://lambda.cs.utu.fi/) may help.

       - Amit
Amit J Patel, Computer Science Department, Stanford University

More information about the Python-list mailing list