Paul Fenwick pjf at perltraining.com.au writes:
for ($foo) {
when ($_ 500) { ++$_ }
when ($_ 1000) { --$_ }
default { say Just right $_ }
}
Ahh... that's exactly what I was looking for. Thanks.
Makes you wonder why the 'given' keyword was added, when
In a message dated Fri, 25 Apr 2008, Moritz Lenz writes:
Paul Fenwick pjf at perltraining.com.au writes:
for ($foo) {
when ($_ 500) { ++$_ }
when ($_ 1000) { --$_ }
default { say Just right $_ }
}
Ahh... that's exactly what I was looking for. Thanks.
AIUI, this is the difference:
given (@foo) {
# this code runs exactly once, topic is @foo
}
vs
for (@foo) {
# this code runs once per item in @foo, topic
# is @foo[0], then @foo[1], etc.
}
So eseentially,
given (@foo)
means the same as Perl5
for ([EMAIL PROTECTED])
Moritz Lenz moritz-at-casella.verplant.org |Perl 6| wrote:
Paul Fenwick pjf at perltraining.com.au writes:
for ($foo) {
when ($_ 500) { ++$_ }
when ($_ 1000) { --$_ }
default { say Just right $_ }
}
Ahh... that's exactly what I was looking for.
Trey Harris trey-at-lopsa.org |Perl 6| wrote:
In 5.10, given seems to copy its argument, whereas for aliases it. (I
haven't looked at the code; maybe it's COW-ing it.) If you add a
Csay Value is now $foo; to the end of the below program, and then
change Cfor to Cgiven and run the program
On Fri, Apr 25, 2008 at 10:39 AM, John M. Dlugosz
[EMAIL PROTECTED] wrote:
Are you saying that Perl 5.10 has given/when ?
Yes. Perl 5.10 has several Perl 6 features back-ported into it,
available via the use feature pragma: say (enables the say()
built-in), state (enables state vars), switch
HaloO,
John M. Dlugosz wrote:
for @foo {...}
is actually short for:
for @foo - $_ {...}
Ups, I missed that one. Do we also have the fill-me idiom
for @foo - $_ {...}
And again the question if this is the same as
for @foo - $_ is ref {...}
Regards, TSa.
--
The
Mark J. Reed wrote:
So eseentially,
given (@foo)
means the same as Perl5
for ([EMAIL PROTECTED])
Just wondering: should given @foo {...} alias to $_, or @_?
Dave Whipp writes:
Mark J. Reed wrote:
So eseentially,
given (@foo)
means the same as Perl5
for ([EMAIL PROTECTED])
Just wondering: should given @foo {...} alias to $_, or @_?
I'd expect it to alias to C$_, on the grounds that everything always
aliases to C$_.
What's the
Smylers wrote:
Dave Whipp writes:
So eseentially,
given (@foo)
means the same as Perl5
for ([EMAIL PROTECTED])
Just wondering: should given @foo {...} alias to $_, or @_?
I'd expect it to alias to C$_, on the grounds that everything always
aliases to C$_.
What's the argument for
The topic should always be $_ unless explicitly requested differently
via the arrow.
Now in the case of for, it might be nice if @_ bound to the entire
collection being iterated over (if any)...
TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:
HaloO,
John M. Dlugosz wrote:
for @foo {...}
is actually short for:
for @foo - $_ {...}
Ups, I missed that one. Do we also have the fill-me idiom
for @foo - $_ {...}
No. There is no concept of output parameters.
And again
Dave Whipp dave-at-whipp.name |Perl 6| wrote:
Mark J. Reed wrote:
So eseentially,
given (@foo)
means the same as Perl5
for ([EMAIL PROTECTED])
Just wondering: should given @foo {...} alias to $_, or @_?
$_. It will contain the whole list as one item, like what Perl 5 does
with
On Fri, Apr 25, 2008 at 01:19:27PM -0500, John M. Dlugosz wrote:
given @foo {
when .length 5 { say That's a long list }
when .length == Inf { say That's a very long list }
when .WHAT ~~ Range { say That's an iterator }
}
Erm, .length is dead, and .WHAT just smells
Mark J. Reed wrote:
The topic should always be $_ unless explicitly requested differently
via the arrow.
Now in the case of for, it might be nice if @_ bound to the entire
collection being iterated over (if any)...
As a perl5-ism:
sub foo { say @_; }
...
given (@bar) {
when ... { foo }
On Fri, Apr 25, 2008 at 01:05:37PM -0700, Dave Whipp wrote:
As a perl5-ism:
sub foo { say @_; }
...
given (@bar) {
when ... { foo }
}
Does perl6 still have some implicit mechanism to say call sub using
current arglist?
Yes, you can do it implicitly with one of callsame, callwith,
To loop back to my earlier question:
In Perl 5.10:
use strict;
use warnings;
use feature qw(switch say);
my $foo = 10;
for ($foo) {
when ($foo 50) { $_++ }
}
say for: $foo;
$foo = 10;
given ($foo) {
when ($foo 50) { $_++ }
}
say
Dave Whipp dave-at-whipp.name |Perl 6| wrote:
Does perl6 still have some implicit mechanism to say call sub using
current arglist?
(No, I'm not arguing to support any of this: just asking the questions)
Yes. You can use 'callsame' and it knows the current argument list.
You can get at
Larry Wall larry-at-wall.org |Perl 6| wrote:
However, foo doesn't mean what it means in Perl 5. It's just the
function as a noun rather than a verb.
Larry
A gerund.
19 matches
Mail list logo