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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |