For loop extended syntax

George Sakkis gsakkis at rutgers.edu
Sun Mar 20 14:33:46 EST 2005


"Kay Schluehr" <kay.schluehr at gmx.net> wrote:

> George Sakkis wrote:
>
> > This would be very
> > useful for list/generator comprehensions, for example being able to
> write something like:
> >
> > [x*y-z for (x,y,z=0) in (1,2,3), (4,5), (6,7,8)]
> >
>
> Looks very appealing, but what to do with
>
> [x*y-z for (x=0,y,z) in (1,2,3), (4,5), (6,7,8)] ?
>
> Should it raise an exception due to a pattern mismatch?

I didn't have in mind to generalize the syntax even more than the respective for function
signatures, therefore this would be syntax error:
SyntaxError: non-keyword arg after keyword arg

> If not how should matching rules apply here?
>
> [x*y-z for (x=0,y=0,z=0) in (1,2,3), (4,5), (6,7,8)]
>
> If in doubt write a vector class that cares about the correct padding (
> or more general and with geometric meaning: select the right hyperplane
> ) and enable to switch between different paddings. This solution is
> both flexible and reusable.
>
> Regards Kay

This was just an example; I think the proposed functionality will be helpful in far more cases than
dealing with geometry or vectors, so I would prefer it to be supported by the language itself.

Regards,
George





More information about the Python-list mailing list