Luke Palmer <[EMAIL PROTECTED]> writes:

>> 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....

For bonus points:

    method Rule::Group::generate_all($self:) {
        for 1 .. Inf -> $i {
            yield $_ for $self.generate($i);
        }
    }

Hmm... I wonder if there's a way of making the basic 'generate' method
lazy too.

-- 
Piers

Reply via email to