On 2006-06-14, Akim Demaille <akim(a)lrde.epita.fr> wrote:
I would like to suggest that for-from loops be sugar for for-in
loops.
You want to desugar a for-from into a for-in to finally unroll the for-in?
Why introduce an extra step when I can immediately unroll the for-from?
I would like to suggest the possibility to use ranges with for-in
loops, which might already be the case.
Not in for-in loops. I don't know why i added these, they come from a dirty
world where almost everything is a string (that is, the shells).
The semantics in ``for i in a, b, c do ... end'' is that i will take
different values (a, b, c) in turn and that's all. It's more about carrying
things around and copying them verbatim, without further modification.
If you want to have something like:
for i in 0..10 do .. end
where the range is going to be expanded in 0, 1, 2, 3, ..., 10, you're giving
it a different semantics!
However, I agree that this kind of sugar could be nice to have. But not in a
for-in loop.
Is there really a real advantage to use ranges when you could simply write
something completely human readable: for i from 0 to 10 do ... end?
Finally, I suggest supporting Cartesian products of ranges.
That's a cool idea!
Finally, I suggest that
for x from 0 to X - 1 do
for y from 0 to Y - 1 do
could be written as
for (x, y) in (0 .. X - 1, 0 .. Y - 1)
Yeah well that's Cartesian products...
or something like that. Maybe
for x, y in 0 .. X - 1 x 0 .. Y - 1
^
Haem... I don't quite like that `x' here :0
Maybe we should require our user to have an APL keyboard and type the proper
symbol ? :-)
where x is the Cartesian product? Nah. Make them tuples? I.e., use
[] again?
for x, y in [0 .. X - 1][0 .. Y - 1]
I like this, since it basically means that arrays are nothing both
variables indexed over ranges that can now be multidimensional.
Hmz, again for-in is not what we want here. But that's a detail. I find this
quite ugly. I think that people (especially the kind of people working on
model-checking) will like the idea about Cartesian products rather than this
weird syntax.
--
SIGOURE Benoit aka Tsuna
_____
/EPITA\ Promo 2008.CSI Rock & tRoll