I would like to suggest that for-from loops be sugar for for-in loops.
I would like to suggest the possibility to use ranges with for-in loops, which might already be the case.
Finally, I suggest supporting Cartesian products of ranges.
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)
or something like that. Maybe
for x, y in 0 .. X - 1 x 0 .. Y - 1
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.
"Akim" == Akim Demaille akim@lrde.epita.fr writes:
I would like to suggest that for-from loops be sugar for for-in loops.
I would like to suggest the possibility to use ranges with for-in loops, which might already be the case.
Finally, I suggest supporting Cartesian products of ranges.
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)
or something like that. Maybe
for x, y in 0 .. X - 1 x 0 .. Y - 1
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.
I would also like to be able to manipulate tuples. Say
x = event_x & y = event_y
->
(x, y) = (event_x, event_y)
likewise for updates and so forth.
"Akim" == Akim Demaille akim@lrde.epita.fr writes:
I would like to suggest that for-from loops be sugar for for-in loops.
I would like to suggest the possibility to use ranges with for-in loops, which might already be the case.
Finally, I suggest supporting Cartesian products of ranges.
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)
or something like that. Maybe
for x, y in 0 .. X - 1 x 0 .. Y - 1
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.
I would also like to be able to manipulate tuples. Say
x = event_x & y = event_y
->
(x, y) = (event_x, event_y)
likewise for updates and so forth.
Also, although I have not really thought in depth about this, but it seems to me that there cannot be a formula, a module, and a variable bearing the same name. Therefore, for consistency, and for a lighter syntax, it might make more sense to use [] for the range, and () for the accesses? Say
s[x][y] '= ...
would be
s(x, y) '= ...
On 2006-06-14, Akim Demaille akim@lrde.epita.fr wrote:
x = event_x & y = event_y
->
(x, y) = (event_x, event_y)
likewise for updates and so forth.
Why not. But is this really necessary? IMHO it's more intelligible in the former version than in the later with tuples.
Also, although I have not really thought in depth about this, but it seems to me that there cannot be a formula, a module, and a variable bearing the same name. Therefore, for consistency, and for a lighter syntax, it might make more sense to use [] for the range, and () for the accesses? Say
s[x][y] '= ...
would be
s(x, y) '= ...
Oh no please :) This is utterly ugly!
On 2006-06-14, Akim Demaille akim@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.