Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
for all(@foo) {...}
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Larry Wall  
View profile  
 More options Apr 24 2005, 1:29 am
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Sat, 23 Apr 2005 22:29:20 -0700
Local: Sun, Apr 24 2005 1:29 am
Subject: Re: for all(@foo) {...}
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.

: Is the whole block run once with 1,2 and 3, or does the
: junction go into the block and autothread each operation?

I expect =all(@foo) would do the former, while all(@foo) would do
the latter, in which case you might as well have used "given" instead.

: for all(1,2,3) {
:    next if $_ < 2;  # testing 1 or all(1,2,3) ?
:    %got{$_} = 1;
: }
: say %got.perl;      # "(('2', 1), ('3', 1))" or "()" ?

Well, { 2 => 1, 3 => 1 } is the more likely notation.

: The "no coupling" in s03 suggests to me that the right
: answer is "(('2', 1), ('3', 1))", but I'm just guessing.

I think =all(@foo) should do what you expect there.  Without the =
it should return { 1 => 1, 2 => 1, 3 => 1 } since there's only one
loop iteration, and it is *not* true that all(1,2,3) < 2.  If you'd
said

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

then it would have done the "next", because 1 < 2.

I should say that I don't see that =all() is different from =any().
They each just produce a list in "random" order.  Though I suppose,
if we say that =one(1,2,3) should randomly pick one value, then
=any(1,2,3) should pick anywhere from 1 to 3 values.  And, of course,
=none(1,2,3) should return a list of all the things that aren't 1, 2,
or 3 in random order.  Maybe a lazy implementation will be beneficial
at that point.  :-)

Larry


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Apr 24 2005, 1:44 am
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Sat, 23 Apr 2005 22:44:47 -0700
Local: Sun, Apr 24 2005 1:44 am
Subject: Re: for all(@foo) {...}
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google