ceylon/ceylon-spec — Issue #82: Sequence comprehensions
Author: gavinking
Created: 2011-12-02 05:52:54+00:00
State: open
Labels: request for feedback

So, it appears to me that we've moved away from the idea of Smalltalk-style arguments for invocation of higher-order functions, and that everyone seems to want a much more conventional syntax for anonymous functions inside positional argument lists. I can live with that. But if that's the case, then I'm going to have to insist that we *at least* need a specialized syntax for comprehensions. There's many many [possible variations](http://en.wikipedia.org/wiki/List_comprehension) of this syntax, but the two possibilities that I think would make most sense are the following:

{ (x**2+y**2)**0.5: x in 0..100 && x%10==0, y in -10..+10 && y%2==0 }

or

{ (x**2+y**2)**0.5: x in 0..100, x%10==0; y in -10..+10, y%2==0 }

I don't have an especially strong preference between these two options. I think the first is more consistent with the rest of our notation, and the second is perhaps slightly easier on the eyes. The second option is also a bit better from a grammar point of view.

Of course, there is also an argument for something like the following syntax:

{ (x**2+y**2)**0.5 for (x in 0..100) if (x%10==0) for (y in -10..+10) if (y%2==0) }

But in this case, I don't think the extra verbosity contributes to readability.

Note that since this is probably something I can desugar in the frontend, we could probably have this feature almost immediately.

Thoughts?