Re: given vs for

2008-04-25 Thread John M. Dlugosz
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.

Re: given vs for

2008-04-25 Thread John M. Dlugosz
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 a

Re: given vs for

2008-04-25 Thread Trey Harris
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

Re: given vs for

2008-04-25 Thread Larry Wall
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 calls

Re: given vs for

2008-04-25 Thread Dave Whipp
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 }

Re: given vs for

2008-04-25 Thread Larry Wall
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

Re: given vs for

2008-04-25 Thread John M. Dlugosz
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 [E

Re: given vs for

2008-04-25 Thread John M. Dlugosz
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

Re: given vs for

2008-04-25 Thread Mark J. Reed
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)...

Re: given vs for

2008-04-25 Thread Dave Whipp
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

Re: given vs for

2008-04-25 Thread Smylers
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<$_>

Re: given vs for

2008-04-25 Thread Dave Whipp
Mark J. Reed wrote: So eseentially, given (@foo) means the same as Perl5 for ([EMAIL PROTECTED]) Just wondering: should "given @foo {...}" alias to $_, or @_?

Re: given vs for

2008-04-25 Thread TSa
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 unavoi

Re: given vs for

2008-04-25 Thread Mark J. Reed
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),

Re: given vs for

2008-04-25 Thread John M. Dlugosz
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 C to the end of the below program, and then change C to C and run the program with values of $foo less than 5

Re: given vs for

2008-04-25 Thread John M. Dlugosz
Moritz Lenz moritz-at-casella.verplant.org |Perl 6| wrote: Paul Fenwick perltraining.com.au> writes: for ($foo) { when ($_ < 500) { ++$_ } when ($_ > 1000) { --$_ } default { say "Just right $_" } } Ahh... that's exactly what I was looking for. T

Re: given vs for

2008-04-25 Thread Mark J. Reed
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])

Re: given vs for

2008-04-25 Thread Trey Harris
In a message dated Fri, 25 Apr 2008, Moritz Lenz writes: Paul Fenwick perltraining.com.au> writes: for ($foo) { when ($_ < 500) { ++$_ } when ($_ > 1000) { --$_ } default { say "Just right $_" } } Ahh... that's exactly what I was looking for. Thanks. Make

Re: given vs for

2008-04-25 Thread Moritz Lenz
> Paul Fenwick 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

given vs for

2008-04-25 Thread Nicholas Clark
Not being familiar with the big picture design* of Perl 6, I'm not able to answer this. I assume that there is a clear reason, but what is it? Nicholas Clark * Heck, I'm also not familiar with the little bits either. - Forwarded message from Ed Avis <[EMAIL PROTECTED]> - Envelope-to: [E