Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by iblech (Friar)
on Jun 03, 2005 at 20:24 UTC ( [id://463399]=note: print w/replies, xml ) Need Help??


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

That is, the ability to loop over an arbitrary number of lists iteratively with a relatively small memory footprint.

Sure, my outer does that, unless I've misunderstood something. It does not return a Code, though, but a lazy list, and it hasn't the same API as NestedLoops, as I was concentrating on the algorithm.

Your solution certainly produces the same output but not 1 at a time and appears to hold everything in memory at once.

Yep, this is as to get even only one item, the helper sub has to be executed recursively several times. I.e., in general:

{ ...; recurse ...; take ...; ...; } # not so good { ...; take ...; recurse ...; ...; } # better (items are yielded ASAP)

Therefore my solution should probably not be included in a library, as the other solutions presented scale much better. I do think that my solution is rather elegant though (no for, few lines of code).

--Ingo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://463399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 22:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found