Christophe Travert:
This little example raises a question if tuples becomes part of
the langage. Should static array have tuple capabilities ?
Why not? Fixed-sized arrays are similar to tuples with uniform
types. Unpacking short arrays in the same way you unpack tuples
*very handy* and it's commonly done in both Python and Haskell
(and probably in other languages too):
In Python:
t = (10, 20)
a, b = t
a
10
b
20
l = [3, 5]
x, y = l
x
3
y
5
In Haskell:
Prelude> let t = (10, 20)
Prelude> let (a, b) = t
Prelude> a
10
Prelude> b
20
Prelude> let l = [3, 5]
Prelude> let [x, y] = l
Prelude> x
3
Prelude> y
5
Besides that, it is easy to emulate your example with a little
library solution. Maybe something like that should be added to
std.range.
What syntax do you suggest?
(Generally tuple unpacking/small array unpacking is a so commonly
done operation that it needs a clean and very nice syntax, so you
often want it as built-in feature).
Bye,
bearophile