in reply to Re^4: Generating lists of strings
in thread Generating lists of strings

What does that have to do with anything?

Everything!

First: Had I found the NestedLoops() syntax intelligable, I might never have sought my own solution, but as is, I would never have come up with the right syntax to do what you've done.

Second: The application I originally wrote nFor() for needed to be as efficient as possible:

c:\test>junk94 Took 0.557000 c:\test>nfor Took 0.09644

Given the very essence of the problems these routines are designed to handle is deeply nested algorithms, that nearly 6x difference can become very significant. Plus, if I need to tweak the function for specific purposes, my code is infinitely simpler to modify than NestedLoops().

c:\test>type junk94.pl #! perl -slw use strict; use Time::HiRes qw[ time ]; use Algorithm::Loops qw( NestedLoops ); sub nFor(&@) { my $cb = shift; NestedLoops([ map [ 0..$_-1 ], @_ ], $cb); } my @digits = 1 .. 3; my $s = time; nFor { my $x = @digits[ @_ ]; } ( 3 ) x 10; printf "Took %.6f\n", time() - $s; c:\test>junk94 Took 0.556000 c:\test>type nfor.pl #! perl -slw use strict; use Time::HiRes qw[ time ]; sub nFor(&@) { my $code = shift; die "First argument must be a code ref" unless ref( $code ) eq 'CO +DE'; my @limits = @_; my @indices = ( 0 ) x @limits; for( my $i = $#limits; $i >= 0; ) { $i = $#limits; $code->( @indices ), ++$indices[ $i ] while $indices[ $i ] < $limits[ $i ]; $i = $#limits; $indices[ $i ] = 0, ++$indices[ --$i ] while $i >= 0 and $indices[ $i ] == $limits[ $i ]; } } my $s = time; my @digits = 1 .. 3; nFor { my $x = @digits[ @_ ]; } ( 3 ) x 10; printf "Took %.5f\n", time() - $s; c:\test>nfor Took 0.10450

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^6: Generating lists of strings
by ikegami (Patriarch) on Jan 24, 2010 at 22:48 UTC

    The application I originally wrote nFor() for needed to be as efficient as possible:

    So make a module. Don't suggest that the OP use and support that big chunk of complex code.

    and your my code is infinitely simpler to modify than NestedLoops().

    Really? Unless each level of nesting is the same, nFor degrades to

    nFor { print map $lists[$_][ $_[$_] ], 0..$#_; } map 0+@$_, @lists;

    I wrote that and I can't even read it.

      Don't suggest that the OP use and support that big chunk of complex code.

      What are you on about?

      If it works for him, then he has no need to "support it". If it doesn't quite work for him, he stands a far better chance of understanding and modifying

      Than

      And far more chance of modifying code that is entirely within his own control. in a timely manner, than of making a persuasive enough case to have a remote author make application specific changes to a complex, generic routine.

      nFor degrades to nFor { print map $lists[$_][ $_[$_] ], 0..$#_; } map 0+@$_, @lists;

      I wrote that and I can't even read it.

      No, neither can I. Nor whatever obscure point you are trying to make by it. Why should it "degrade"? Unless as a result of your corrosive comments.

      I offered the OP a simple, correct, perlish solution to his question. As have others.

      It is his choice to use whichever he finds most suitable.

      Why the **** are you jumping up and down over my correct solution, whilst ignoring the incorrect ones?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Why the **** are you jumping up and down over my correct solution

        I'm "jumping up and down" on the comments you made since I mistakenly thought your solution wasn't correct.

        whilst ignoring the incorrect ones?

        I don't know them to be incorrect. You're the only one who reimplemented NestedLoops, and my comments don't juast apply to your code and your comments.