Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^4: Perl6 Contest #2: P6 That Doesn't Look Like P5

by tall_man (Parson)
on Jun 06, 2005 at 21:29 UTC ( #464095=note: print w/replies, xml ) Need Help??

in reply to Re^3: Perl6 Contest #2: P6 That Doesn't Look Like P5
in thread Perl6 Contest #2: P6 That Doesn't Look Like P5

Roy, I tried your code on the documentation example:
my $N = 4; my $depth = 3; my $i2 = nested_for([ [ 0..$N ], ( sub { [$_+1..$N] } ) x ($depth-1), ]); print "@args\n" while @args = $i2->();

There seems to be a problem when the range hits the top. The output is:

0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 0 4 1 2 3 1 2 4 1 3 4 1 4 2 3 4 2 4 3 4 4

Replies are listed 'Best First'.
Re^5: Perl6 Contest #2: P6 That Doesn't Look Like P5
by Roy Johnson (Monsignor) on Jun 06, 2005 at 23:36 UTC
    That makes sense: the range ends up being [5..4], which is a no-iteration loop. What do you think should be the output?

    NB: my code does not run under 5.8.1 (on a Mac). I don't know why, and I can't get 5.8.6 to compile. Grrr. I hate it when my PC works better than my Mac.

    Update: and to answer my own question, I looked at what NestedLoops does. Sensibly enough, it does no iterations when there's a no-iteration loop. You can get this behavior by making the last line of nest be return((@out and @in) ? (@out, @in) : ());

    Caution: Contents may have been coded under pressure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://464095]
[RonW]: Cool, stevieb
[stevieb]: Not to mention, the bundle has a C# IDE, so I can finally rid myself of using Visual Studio (or just vi/vim) when I work on berrybrew
[RonW]: I continue to avoid C#. And successfully

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-02-20 21:14 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (302 votes). Check out past polls.