Front page | perl.perl6.language |
Postings from March 2011
lol context and X
Thread Next
From:
Aaron Sherman
Date:
March 31, 2011 14:16
Subject:
lol context and X
Message ID:
AANLkTinHOJZbZz64i_=1ko=gGcL_q180abv-aHXLrb5x@mail.gmail.com
[This might be better suited to p6c if it turns out that this is a
bug, but I'll assume it's not to start...]
So, last night sorear said, "I might write the loop as for 2 .. $lim X
2 .. $lim -> $a, $b {"
I played around with this a bit, and I'm unclear on how this works.
Here's some examples that I tried:
# parens on the arglist causes flattening?
$ ../rakudo/perl6 -e 'for 1 .. 2 X 4 .. 5 -> ($a, $b) { say $a.perl, $b.perl }'
Not enough positional parameters passed; got 0 but expected 2 in sub-signature
in <anon> at line 1
in main program body at line 1
# Lack of parens gives lol context?
$ ../rakudo/perl6 -e 'for 1 .. 2 X 4 .. 5 -> $a, $b { say $a.perl, $b.perl }'
14
15
24
25
# Default context is flat?
$ ../rakudo/perl6 -e 'for 1 .. 2 X 4 .. 5 { say .perl }'
1
4
1
5
2
4
2
5
# lol just not implemented in rakudo, or am I doing it wrong?
$ ../rakudo/perl6 -e 'for lol 1 .. 2 X 4 .. 5 { say .perl }'
Could not find sub &lol
in main program body at line 1
# capture flattens? that seems really non-intuitive
$ ../rakudo/perl6 -e 'for |(1 .. 2 X 4 .. 5) { say .perl }'
\(1, 4, 1, 5, 2, 4, 2, 5)
# hyper-. flattens?
$ ../rakudo/perl6 -e '(1 .. 2 X 4 .. 5)>>.join(",").say'
14152425
Can someone explain why these all behave so differently, and why we
chose to flatten so aggressively in so many cases, but not in some
others?
--
Aaron Sherman <ajs@ajs.com>
P: 617-440-4332 Google Talk: ajs@ajs.com / aaronjsherman@gmail.com
"Toolsmith" and developer. Player of games. Buyer of gadgets.
Thread Next
-
lol context and X
by Aaron Sherman