There is a module called Quantum::Superpositions , among other things it also allows binary functions to receive quantum parameters. We can extend that to an arbitrary number of parameters. This can serve as a replacement for Algorithm::Loops. Basically you pack up the arguments in a structure like:

[a1,[a2,[a3,...[an,an1]]]..]

the nice property is that each time you look at a ai you get a different value :) In fact, the only thing that concerns you as a programmer , is that you will get every possible combination of the parameters once and only once.

use strict; use warnings; # 18-01-2010 # cartesian product for 3 or more sets using Quantum::Superpositions # works because BINARY in Q::S allows to make quantized functions like + U and p. sub p { return \@_; } sub U { my $i = $_[1]; my @element; # an element of the cartesian product if(ref($i) eq 'ARRAY') { while(1){ push @element,$i->[0]; $i=$i->[1]; last unless ref($i) eq 'ARRAY'; } }; @element=($_[0],@element,$i); print join(' ',@element)."\n" if ref($_[1]) eq 'ARRAY'; } use Quantum::Superpositions BINARY => ['main::U','main::p']; #U(any(1..2),p(any(9..13),p(any(0..1),p(any(2..4),any(5..8))))); U(any(1..2),p(any(2..4),any(5..10)));

In reply to Quantum tuples by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.