Python and Smalltalk call models (was Re: Why aren't we all speaking LISP now?)

Michael Hudson mwh at python.net
Mon May 14 19:31:58 EDT 2001


James_Althoff at i2.com writes:

> Fredrik writes:
> >what exactly is the difference between Python's call model
> >and Smalltalk's message passing?  consider something like:
> >
> >    spam.egg(bacon)
> >
> >couldn't this be seen as sending the message "egg" to the
> >object "spam"?
> >
> >Cheers /F
> 
> Pretty much the same.  Two areas of difference:
> 
> 1) In Python, "egg" could be an instance attribute that references a bound
> method associated with the *instance* "spam" (i.e., that lives in the dict
> of "spam") --

>  although I believe this occurs not so frequently in practice

This I agree with.

> (you have to create the bound method using "new.instancemethod" in the
> "new" module to make this work).

This, however, isn't true:

>>> class C:
...  def foo(self):
...   print 1
... 
>>> spam = C()
>>> spam.eggs = spam.foo
>>> spam.eggs()
1
>>> spam.__dict__['eggs']
<method C.foo of C instance at 0x81c78e4>

> Smalltalk would always look in the method
> dict of the class of "spam" to find the method "egg" -- IOW, Smalltalk
> would not try to find an instance-specific method first.
> 
> 2) If "spam" is a *class object*, then in Python "spam.egg(bacon)" would
> mean the same as "bacon.egg()" -- assuming that "bacon" is an instance of
> class "spam".  In Smalltalk, it would mean "look in the method dict of the
> *class* of class object 'spam' to find the method 'egg'; then invoke method
> 'egg' on class object 'spam' passing in 'bacon' as an arg."  In Smalltalk
> class objects are also instances -- of metaclasses -- so the message/method
> lookup mechanism is the same for both "class methods" and "instance
> methods".
> 
> Both of the above -- especially the second -- contribute to making "class
> methods" somewhat problematic in current Python.

This is certainly true again.

Cheers,
M.

-- 
  The only problem with Microsoft is they just have no taste.
              -- Steve Jobs, (From _Triumph of the Nerds_ PBS special)
                         and quoted by Aahz Maruch on comp.lang.python



More information about the Python-list mailing list