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

iblech,
Call it what you want, what I am trying to replicate is NestedLoops from Algorithm::Loops. That is, the ability to loop over an arbitrary number of lists iteratively with a relatively small memory footprint. Your solution certainly produces the same output but not 1 at a time and has everything in memory at once. That aside, it certainly helps me learn more Perl6 and exposes others as well.

Cheers - L~R

  • Comment on Re^2: Perl6 Contest #2: P6 That Doesn't Look Like P5

Replies are listed 'Best First'.
Re^3: Perl6 Contest #2: P6 That Doesn't Look Like P5
by iblech (Friar) on Jun 03, 2005 at 20:24 UTC
    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