prototypes in Python [was: what is good in Prothon]
Jonathan Gardner
jgardner at jonathangardner.net
Sun May 2 02:55:21 EDT 2004
has.temp2 at virgin.net (has) wrote in message news:<69cbbef2.0404281050.4dc3380e at posting.google.com>...
> # Define object 'foo'
> foo = Object()
> foo.a = 3
> foo.b = 3
> foo.multiply = lambda target:target.a*target.b
>
I think this is the syntactic sugar that is missing: anonymous
functions come in one breed only: lambdas. This example fits neatly
into a lambda function, but more complicated examples won't.
For instance, you can't write:
def foo.multiply(self):
return self.a * self.b
I would imagine an easy way to do this would be to have this be
acceptable:
foo.multiple = def(self):
returns self.a * self.b
This will create an anonymous function and store it in foo.multiple.
I'll admit that classless OO programming looks neat. The only thing
that I can't see an obvious way of doing is to share a value or method
across multiple objects. For instance:
class A:
number = 0
def __init__(self):
number += 1
def __del__(self):
number -= 1
How would you share "number" across a similar class of objects?
Also, it kind of renders the question, "What kind of object is this?"
meaningless. There are no /kinds/ anymore, at least not built into the
language. You can go ahead and create objects that are classes, and
then make objects that have an attribute called "class", I guess.
I do enjoy seeing different perspectives from other communities. It
helps me get a new perspective with my own programming.
More information about the Python-list
mailing list