[Python-Dev] Features for Python 2.0

Tim Peters tim_one@email.msn.com
Tue, 25 Jul 2000 23:11:53 -0400


[Greg Wilson]
> I would also like to volunteer to repeat the "simultaneous loop" syntax
> experiment with list comprehensions, i.e. see whether what's being
> proposed lines up with people's pre-existing intuitions.

[Guido]
> Please do!
>
> Though I have no doubt of the outcome:
>
>   [x+y for x in [10, 20, 30] for y in [1, 2, 3]]
>
> will be almost universally understood to mean
>
>   [11, 12, 13, 21, 22, 23, 31, 32, 33].

I'm not sure about that!  Greg hangs out with functional programmers and old
Fortran-heads.  Fortran has a handy construct called "implied DO (loops)" in
I/O statements, and in those the *innermost* (leftmost) shorthand loop
varies fastest.  So I expect the Fortran'ers to guess

    [11, 21, 31, 12, 22, ...]

I agree the experiment is worth trying, but I'm not sure we're observing
anything other than experienced programmers' prior language-dependent
conditioning ... which would also explain why neither Greg's functional nor
Fortran guinea pigs had any concept of lockstep iteration across multiple
loop controls.

BTW, an MxN slice of a 2D array A in Fortran will often show up in an I/O
stmt as

 ... ((A(I,J), I=1,M), J=1,N) ...

and the "innermost fastest" rule relates directly to Fortran's oddball
decision to use column-major array storage:  the natural way to write the
I/O using implied DOs caters to varying the first index fastest (==
contiguous memory locations under column-major storage).  It's not like
there's a *profound* reason behind this <wink>.