"sins" (aka, acknowledged language problems)

Bijan Parsia bparsia at email.unc.edu
Sun Dec 26 18:37:43 EST 1999


skaller <skaller at maxtal.com.au> wrote:

[snip]
> 
> Unfortunately, new control structures are easy to introduce,
> but we don't want to litter the language with TOO many.
> Here's one that is going in to Viper, when I can
> come up with the right keyword:
> 
>       ifor k,v in e: ..
> 
> where k and v are the keys and values of a dictionary,
> or, the indices and values of a sequence. This is
> commonly needed, instead of:
[snip]

NewtonScript just uses 'foreach' (replace "frame" with "dict" in the
following:

> foreach [slot,] value [deeply] in {frame | array} 
> {collect | do} expression 
> Using the foreach iterator is one way you can access data stored in frames
> or arrays. This iterator executes once for each element in an array or
> frame allowing you to either iterate an expression over each value stored
> in an array or frame, or to collect data during each iteration. In an
> array, iteration begins with the first element of the array, element 0. In
> a frame the starting point and subsequent order of iteration is
> unpredictable since frame slots are not stored in any particular order.

(I take it, upon reflection, that 'foreach' is the NS spelling of 'for x
in y'

So, you could just use 'for' with the added notion that providing two
variables gives you the index in the first one.

As I recall, this didn't lead to any confusion in NS.

I don't know if this conflicts with already legal Python. But it seems
much preferable than a different keyword.

Cheers,
Bijan Parsia.



More information about the Python-list mailing list