Algorithm::Loops will now find my latest module. It includes a few looping constructs that I've posted to PerlMonks over the years (from the README.txt):

Algorithm::Loops - Looping constructs: NestedLoops, MapCar*, Filter, and NextPermute*

Algorithm::Loops provides several functions for doing different types of looping constructs:

Filter

Similar to C<map> but designed for use with s/// and other reflexive operations. Returns a modified copy of a list.

MapCar, MapCarU, MapCarE, and MapCarMin

All similar to C<map> but loop over multiple lists at the same time.

NextPermute and NextPermuteNum

Efficiently find all (unique) permutations of a list, even if it contains duplicate values.

NestedLoops

Simulate C<foreach> loops nested arbitrarily deep.

I'm posting this announcement because several people have asked for one or more of these routines to be made available in a module on CPAN, but even more so to make it easy for people to give me feedback on aspects of the module.

In particular, I'm interested in whether the documentation is clear. But any suggestions are welcome.

                - tye

Replies are listed 'Best First'.
Re: Algorithm::Loops released (docs)
by tye (Sage) on Sep 29, 2003 at 04:35 UTC

    To make it as easy as possible for people to comment on this, here is the module's documentation and a link to the copy on search.cpan.org.

    It certainly isn't "short", so you might want to reply to the root node, not to this one.

    I'm mostly interested in whether the documentation is clear.

    The formatting is mostly just stolen from http://search.cpan.org/.

                    - tye
Re: Algorithm::Loops released (tests)
by tye (Sage) on Sep 29, 2003 at 04:47 UTC

    The module includes two test sets.

    The first, assert.t, tests for the common failure cases and the source for it is below (or see the copy on search.cpan.org).

    Note that the script is actually two scripts in one: The test script and a script to update the "#14#" comments for which test number applies to which line of code.

    Since I'm testing fatal errors, all of the code to be tested appears after the __END__ tag. I particularly like the way I manage to report the correct file name and line numbers in the error messages.

    Note that part of the code to set the line number offset for the test run is located in the code that renumbers the test cases (which doesn't get run during a test run).

    The second, basic.t, tests basic functionality and the source for it is below (or see the copy on search.cpan.org).

    Note that it has a quite different way of including the second script that updates the test number comments in the "real" part of the script.

                    - tye
Re: Algorithm::Loops released
by belg4mit (Prior) on Sep 29, 2003 at 17:37 UTC
    my $line= Filter {chomp} ''.<STDIN>;
    It might be clearer (codewise, and to avoid the need for commentary) to change this to:
    my $line= Filter {chomp} readline(STDIN);
    The different MapCar* functions are only different in how they deal with being pqssed

    NextPermute sounds cool.

    PS> Around line 955: '=item' outside of any '=over'

    --
    I'm not belgian but I play one on TV.

Re: Algorithm::Loops released (code)
by tye (Sage) on Sep 29, 2003 at 04:53 UTC

    At this point, I might as well include the code...

    So here it is (minus the POD) and a link to the copy on search.cpan.org.

    Most of the routines include improvements over the versions available on PerlMonks. You might also want to check out the example scripts included with the module.

    I'd like to thank the Sharp Zaurus for making this module possible.

                    - tye
Re: Algorithm::Loops released
by graff (Chancellor) on Sep 30, 2003 at 06:26 UTC
    (How much trouble would it be to have the CPAN installation put Algorithm::Loop.3 into the standard man/man3 directory? and you should probably run a spell-checker on it...)

    Personally, I was grateful for this initial paragraph under "FUNCTIONS":

    Algorithm::Loops provides the functions listed below. By default, no functions are exported into your namespace (package / symbol table) in order to encourage you to list any functions that you use in the "use Algorithm::Loops" statement so that whoever ends up maintaining your code can figure out which module you got these functions from. (emphasis added)

    Your sample code for sorting "both alphabetically and numerically at the same time" threw me off for a few reasons... First, it wasn't clear that it would work:

    my @sorted= Filter { s#\d{2}(\d+)#\1#g } sort Filter { s#(\d+)# sprintf "%02d%s", length($1), $1 #g } @data;
    Looks to me like you should include "e" with "g" at the end of that second s### (same might apply to the "HTML templating" example). Also, why use "\1" (rather than $1) in the right-hand side of the first s###? And maybe provide at least one extra line of code at the beginning, like:
    my @data = qw/a.1 a.5 a.11 b.3 b.15/;
    or something equivalent, along with the intended output, to clarify what kind of sorting you mean (and to make sure the snippet really produces the intended result).

    For the "MapCar*" discussion, I'd skip the arcane remarks about using map in a scalar context (it doesn't aid in using your module). The "Formatting a date-time" example seems overly "golfed" (that is, obfuscated). Maybe my mileage is just way different, but it didn't yield what I think was expected:

    use Algorithm::Loops (MapCarE); my $dateTime= join "", MapCarE { sprintf "%02d%s", pop()+pop(), pop() } [ (localtime)[5,4,3,2,1,0] ], [ 1900, 1, (0)x4 ], [ "// ::" =~ /./g, "" ]; print $dateTime,$/; print scalar localtime(),$/; ## for a more familiar view __OUTPUT__ 1900103018003000100130037 Tue Sep 30 01:13:37 2003
    It took me a while to figure out that it works better with "shift()" instead of "pop()" -- if you actually want to keep this example. (Later examples using "pop()" might have the same property.)

    The NestedLoops stuff is a bit hard to grok, but in this case the examples do help (especially since they seem to work "out of the box"). The conceptual problem here, I think, is the cognitive disconnection between a real nested loop structure vs. a linear set of parameters (often combined with the "x" operator) that describe such a structure.

    The challenge will be to compose a description of the NestedLoop syntax that "resonates" somehow (relates more or less directly) with the traditional concept of nesting. Maybe something like a "3-D" example would help, too; e.g. given axes that extend 8 units on X, 6 units on Y, and 3 units on Z, populate the 3-D matrix in some interesting (but not too complicated) way, like initializing all points in the successive Z planes to -1, 0 and 1. (But then again, maybe that wouldn't help...)

    Edit by tye, change PRE to BLOCKQUOTE

Re: Algorithm::Loops released
by artist (Parson) on Sep 29, 2003 at 15:10 UTC
    ++ to tye.

    First mention was at Coming soon: Algorithm::Loops as a reply to one of my math-puzzle. I am sure lots of people will be happy about this.

    artist
    ===================================================
    Perl is fast.. So I spend more time doing fast things