1.6 features

Moshe Zadka moshez at math.huji.ac.il
Thu Aug 3 01:02:05 EDT 2000


On Wed, 2 Aug 2000, Edward C. Jones wrote:

> How do languages in which everything is an object handle
> "'moshe'.find('sh')"? 

Depends on the language: one example is Python, and it treats it just
fine. Just like [].append() and [1,2,3].sort()

> It is normal that literals are treated as the
> name of an instance?

If you substitute "object" for "instance", then that has always been
the case in Python. 1 is an object of type int, and "111" is an object
of type string. (Well, at least since Python 1.2 -- my experience doesn't
go that far back)

> How does Smalltalk handle this?

1 + 2 ==> send the message "+" with argument 2 to the object 1. Not 
really different from the way Python does that.

> Might we
> eventually see "1.__radd__(2)"?

Perhaps -- if a future version of Python handles the type/class dichotomy
problem gracefully, then that might indeed be what 2+1 means (well, not
really, because in that case, 2.__add__(1) will be called. And, the
fact that 2. is a valid literal means you'd have to do (2.)__add__(1).
But, hey, anything for an alternative ugly syntax -- you might as well
stick to 2+1 and trust the compiler to do the transformation itself)

--
Moshe Zadka <moshez at math.huji.ac.il>
There is no IGLU cabal.
http://advogato.org/person/moshez





More information about the Python-list mailing list