ANN: Pyrex 0.4.3

Matthias Baas baas at ira.uka.de
Wed Aug 28 04:25:30 EDT 2002


On Wed, 28 Aug 2002 13:45:16 +1200 (NZST), Greg Ewing
<greg at cosc.canterbury.ac.nz> wrote:
>One final comment about for-from: The other reason I introduced
>it is that I wanted to find out what it would be like to use
>such a construct, and this seemed like a good opportunity to
>get some experience with it.

Well, in my earlier posting I wasn't aware that someone could have
altered the range() function which could have changed its semantics.
So I realize that the optimizations I was suggesting are not as easy
as I thought at first glance.

However, there are still some points left why I think a different
for-syntax would be appropriate. Here's what I criticise about the
current version:

- It uses an existing keyword ("from") in a context that's completely
different from its original use (importing modules). In general, I
believe that such a doubly usage of keywords is a bad design.

- It neither resembles Python nor C, but is a completely new
construct. All the other stuff in Pyrex so far was solved rather
elegantly and was added in a quite intuitive way that looked familiar
to Python/C programmers. 


Here are some more alternatives which I would all prefer before the
current syntax:

- Instead of a new syntax, the original C syntax could be allowed for
C variables:

  cdef int i  
  for(i=0; i<10; i=i+1):
    print i

- There could be a (pseudo) range() function (called crange() for
example) that always has the same semantics than the builtin range.

  cdef int i  
  for i in crange(10):
    print i

- Or as someone else suggested, there could be the possibility to
declare range() as being the original range(). This means, all
occurences of range() aren't actually referring to __builtin__.range()
but are referring to a range() that has the original semantics.

Meanwhile I think using the original C syntax would be the best way to
go, because...

- ...it doesn't mess with the semantics of existing Python functions
and doesn't require any assumptions that could possibly be wrong.

- ...it's a familiar construct, so I don't have to learn and remember
any new syntax.

- ...it allows to express all the loops I could write in C directly
(for example, using an increment different from 1).

- ...it's "WYSIWYG" :) If I write a Python-loop I will get a
Python-loop and if I write a C loop I will get a C loop. 


ok, I think I've expressed all my concerns and even provided some
alternatives to think about, so that's all from my side. Of course,
it's up to Greg to make the final decision.
But whatever the syntax will be, Pyrex still remains the
Tool-Of-The-Year for me.... :)

- Matthias -




More information about the Python-list mailing list