[maemo-developers] New project idea, pygtk questions, and a toolkit
From: Sean Luke sean at cs.gmu.eduDate: Mon Mar 19 21:21:09 EET 2007
- Previous message: New PyMaemo svn repository
- Next message: Summer Of Code Proposal: Wifi Localization
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Marius Gedminas wrote (a month ago!):
> On Mon, Feb 19, 2007 at 12:41:15PM -0500, Sean Luke wrote:
>
>> - Why is it in python that you can attach a function, and an instance
>> variable, to an instance, but you cannot attach a method?
...
> There's a distinction between functions, unbound methods and bound
> methods. When you assign a function to a class attribute, you get a
> unbound method.
This is an imaginary distinction only Python makes, and not for any
good reason. It looks to me like it's historical warts. :-( For
example, in NewtonScript (and Self, etc.), there's no distinction at
all between bound and unbound methods and functions: they're all
functions, and depending on the context in which they're called they
may or may not have 'self' bound to something interesting. CLOS
behaves similarly in this respect.
> If by "anonymous" you mean "a function that does not have a name",
> then
> you can't. You can define a named function in the middle of another
> function.
Yeah, that's what I had figured. :-(
>> I'd like to do this in python with the following equivalent (but
>> invalid) syntax:
>>
>> myButton= Button()
>> myButton.printme = lambda self:
>> print("hi there")
>> print("I am " + self)
>
> myButton = Button()
> def printme(self=myButton):
> print "hi there"
> print "I am", self
> myButton.printme = printme
Sadly, not the same thing for two reasons. First, because depending
on context we may have polluted the global namespace, and at least
the local namespace, with an arbitrary function name; and second,
depending on context this definition may not permit closures.
Thanks very much for your response anyway, Marius, it was helpful. I
had just hoped for better from this language but that's life.
Sean
- Previous message: New PyMaemo svn repository
- Next message: Summer Of Code Proposal: Wifi Localization
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
