satyr/coco — Issue #109: Nested list comprehensions order
Author: gkz
Created: 2012-01-27 00:45:10+00:00
State: open

First of all, great work on Coco! List comprehensions are flat as they should be. The order in which they are constructed however is different from how it is regularly done in other languages - this seems to be an artifact from Coco's CoffeeScript ancestry. The `for` the furthest to the right should be the fastest.

e.g.
It is translating

"#x#y" for x of [1, 2, 3] for y of ['a', 'b', 'c']
as

for y of ['a', 'b', 'c']
for x of [1, 2, 3]
"#x#y"
instead of the expected:

for x of [1, 2, 3]
for y of ['a', 'b', 'c']
"#x#y"

---
An example:

In **Coco**:

"#x#y" for x of [1, 2, 3] for y of ['a', 'b', 'c']
is

1a,2a,3a,1b,2b,3b,1c,2c,3c

While in **Python**

["{0}{1}".format(x, y) for x in [1, 2, 3] for y in ['a', 'b', 'c']]
is

['1a', '1b', '1c', '2a', '2b', '2c', '3a', '3b', '3c']

and in **Haskell**

[(show x) ++ y | x <- [1,2,3], y <- ["a","b","c"]]
is

["1a","1b","1c","2a","2b","2c","3a","3b","3c"]