> On Thu, Apr 03, 2003 at 07:29:37AM -0800, Austin Hastings wrote:
> >This has been alluded to before.
> >
> >What would /A*B*/ produce?
> >
> >Because if you were just processing the rex, I think you'd have to
> >finish generating all possibilities of A* before you began iterating
> >over B*...
>
> The "proper" way would be to first produce all possibilities of length n
> before giving any possibility of length n+1.
>
> ''
> 'A'
> 'B'
> 'AA'
> 'AB'
> 'BB'
> 'AAA'
> 'AAB'
> ...
>
> I haven't spent a milisecond of working out whether that's feasible to
> implement, but from a theoretical POV it seems like the solution.
Well, I'm not certain there is really a "proper" way. But sure, your
way is doable.
use Permutations <<permutations compositions>>;
# Generate all strings of length $n
method Rule::Group::generate(Int $n) { # Type sprinkles :)
compositions($n, [EMAIL PROTECTED]) ==> map {
my @rets = map {
$^atom.generate($^n)
} zip(@.atoms, $_);
*permutations([EMAIL PROTECTED])
}
}
How's that for A4 and A6 in a nutshell, implementing an A5 conept? :)
I hope I got it right....
Provided each other kind of rx element implemented generate, that
returned all generated strings of length $n, which might be zero.
This would be trivial for most other atoms and ops (I think).
Oh, compositions($a,$b) is a function that returns all lists of length
$b whose elements sum to $a. Yes, it exists.
I have a couple syntax questions about this if anyone knows the answers:
$^atom.generate($^n)
I want @rets to be an array of array refs. Do I have to explicitly
take the reference of that, or does that work by itself?
zip(@.atoms, $_)
I want the array ref in $_ to be zipped up with @.atoms as if $_ were
a real array. If this I<is> correct, am I allowed to say:
zip(@.atoms, @$_)
for documentation?
Also, related to the first question:
*permutations([EMAIL PROTECTED])
Does that interpolate the returned list from permutations right into
the map's return, a la Perl5? Do I need the * ?
Wow, 5 unobfuscated friggin lines! This language is gorgeous!
Luke