Piers Cawley wrote:
> $ints_from = ^1 => sub {$ints_from->(^1+1)};
> $ints = $ints_from->(1);
I think pairs should use array range syntax ".." and be folded
into the array generator RFC (or at least referenced in that RFC).
In particular, using a pair in an array context should interpret
the pair as a sequence -- just like generated arrays.
my $pair = 1..4;
key $pair == 1
value $pair == 4
@{$pair} == (1, 2, 3, 4)
my $list = 1..2..3..nil;
key $list == 1
value $list == 2..3..nil
@{$list} == (1, 2, 3)
Of course in array context these would be lazily generated, i.e. streams.
For complex generated arrays, the left or right hand side of the pair
can be a bounding object which might have a generator function or step
value.
That's three special cases for turning a pair into a stream, but at
least it confines all this new magic to a single place in the language.
I think the idea that => is "just another comma" is pretty widespread
now.
BTW, regardless of whether => or .. are used, the operator has to be
right associative with low precedence. 1..2..3 should be 1..(2..3) and
not (1..2)..3. 1..$a+b..$d*e should be 1..(($a+b)..($d*e)).
Assignments to (key $pair) and (value $pair) should also do the right
thing and replace the key and value in the pair.
The use of => for named parameters IMHO is very distinct from pairs and
should be an implementation detail.
- Ken
P.S. I think it's funny that this RFC proposes a head and tail function
that are nearly as obscure as Lisp's car and cdr.