Status of PEP's?

James_Althoff at i2.com James_Althoff at i2.com
Tue Mar 5 17:16:58 EST 2002


[Samuele Pedroni]
> Smalltalk try to deal with such
> corners compesating
>  vaguely mimicking english:
>
> 1 to: 20 do: [...].
> 10 timesRepeat: [...].
>
> These forms in some sense (my
> very personal impression)
> try to hide that 1 is an object here,
> not to underline that.

Interesting observation.  But actually, we very much chose those forms to
"underline" not to "hide" the fact that numbers are first-class objects in
Smalltalk (as they are also in Python).  A Smalltalker sees "10
timesRepeat: [...]" and thinks "send the timesRepeat message to (i.e.,
invoke the method on) the integer object 10 passing along the block [...]
as an argument in order to execute the block 10 times".  Smalltalkers
delight in seeing everything interpreted as messages sent to (i.e., methods
invoked on) objects.  It was a deliberate design decision to *not* add
special syntax for control structures specifically so that control
structures would be seen as "objects responding to messages/methods" just
like everything else.  We wanted a language whereby *everything* could be
interpreted as "objects responding to messages/methods".

>
> What about "for i in 10"
> from this angle of view ?

I like the idea of a for-loop getting an iterator from the target and then
iterating on the produced values.  And, as PEP 276 says, it seems simple,
useful, and practical to have iter(n) produce 0,1,...,n-1 (particularly in
for-loops).  I like the idea of integers being first-class objects.  I like
the idea of integers having methods.  I don't see any reason why one should
pretend that integers aren't first-class objects.  Or why one should try to
hide the fact that class int has methods.  But then, I'm hopelessly
indoctrinated -- although, I'm perfectly content to write abs(n) (just in
case any -bots that shall remain nameless are listening) <wink>.

Jim





More information about the Python-list mailing list