Python vs. Io

Hannu Kankaanp?? hanzspam at yahoo.com.au
Mon Feb 2 16:17:14 EST 2004


alloydflanagan at comcast.net (A. Lloyd Flanagan) wrote in message news:<e838aa6e.0402020730.3d45c9b1 at posting.google.com>...
> LittleDanEhren at yahoo.com (Daniel Ehrenberg) wrote in message news:<711c7390.0401291301.3f95794 at posting.google.com>...
> > Can anyone show me how to so much as alias "for" to "each" in Python
> > or allow block syntax at all without hacking the C source code?
> > 
> I think the point is, why on earth would you want to do something like
> that?  If you want a language you can use to make programs that make
> no sense to anyone but the author, Perl should be more than sufficient
> for your needs.

The point is that implementing your own "for" is something you can't
do in Python very nicely, so it's a proof that Io can achieve
genuinely higher abstraction levels on this part. Implementing
"for" again with a new name probably wouldn't make anyone
happy, but such power opens a set of tricks and idioms to
be used in real code to solve real problems, that wouldn't
be possible in Python without kludgy syntax.

Here's a normal loop:

bar = 0
for x in range(10):
    bar += x

Here's the same using a custom loop:

bar = [0]
def temp(x):
    bar[0] += x
for_each(range(10), temp)

That is just so damn ugly. I want to be able to define (e.g.)

bar = 0
for_each(x, range(10)):
    bar += x

Now tell me which of these two lowermost forms looks
better and makes more sense? For examples that don't
just make aliases of existing syntax, see the
Lisp vs Python thread that was here a few months ago
(sorry, can't remember it's topic name).

BTW, Python can be used to make programs that make
no sense as well. (due to Ulf Bartelt:)

print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,
i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y
>=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(
64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy
))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)

The real question is if the language *allows* a sensible
programmer to write clear, understandable code even in hard
problem domains.

But this is nothing but my humble opinion without actually
knowing anything about Io.. Maybe it isn't that good. I wasn't
really arguing for Io but for better abstractions.



More information about the Python-list mailing list