develooper Front page | perl.perl6.language | Postings from April 2005

Re: for all(@foo) {...}

Thread Previous
From:
Larry Wall
Date:
April 23, 2005 22:44
Subject:
Re: for all(@foo) {...}
Message ID:
20050424054447.GA29737@wall.org
On Sat, Apr 23, 2005 at 10:29:20PM -0700, Larry Wall wrote:
: On Sun, Apr 24, 2005 at 03:02:16PM +1000, Brad Bowman wrote:
: : Hi,
: : 
: : I'm trying to understand the following section in S03:
: : 
: :   S03/"Junctive operators"
: : 
: :   Junctions are specifically unordered.  So if you say
: :     for all(@foo) {...}
: :   it indicates to the compiler that there is no coupling between loop
: :   iterations and they can be run in any order or even in parallel.
: : 
: : Is this a "for" on a one element list, which happens to
: : be a junction, or does the all() flatten?
: 
: No, S03 is probably just wrong there.  Junctions are scalar values, and
: don't flatten in list context.  Maybe we need something like:
: 
:     for =all(@foo) {...}
: 
: to iterate the junction.

For the purposes of S03 it would have been better to use an example
without list context like:

    -> $x {...}(all(@foo))

or maybe

    all(@foo).each:{...}

I think that "given" specifically does not autothread it's block, so

    given any(1,2,3) {...}

matches each case against any(1,2,3).  That is, there is an MMD variant
of "given" that accepts a Junction, which disables autothreading.

Or maybe S03 really just wants to say that

    if all(@foo).each:{...} {...}

is allowed to stop evaluating cases in "random" order when it gets
the first false value back from .each, while

    if any(@foo).each:{...} {...}

is allowed to stop as soon as it gets a true value.

Larry

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About