> just an aside, and a bit off-topic, but has anybody considered
> hijacking the regular expression engine in perl6 and turning it into
> its opposite, namely making *productions* of strings/sounds/whatever
> that could possibly match the regular expression? ie:
> 
> a*
> 
> producing
> 
> ''
> a
> aa
> aaa
> aaaa
> 
> etc.
> 
> I could think of lots of uses for this:
> 
>       1) test data for databases and programs.
>       2) input for genetic algorithms/code generators
>       3) semantic rules/production of random sentences.
> 
> In fact, I foresee a combo of 2,3 and some expert system somewhere
> producing the first sentient perl program. ;-)

Yeah, it seems like a neat idea.  It is if you generate it
right... but, fact is, you probably won't.  For anything that's more
complex than your /a*/ example, it breaks down (well, mostly):

    /\w+: \d+/

Would most likely generate:

    a: 0
    a: 00
    a: 000
    a: 0000

Or:

    a: 0
    a: 1
    ...
    a: 9
    a: 00
    a: 01

ad infinitum, never getting to even aa: .*

But I guess then you'd see a lot more quantifiers and such.

    /\w+<8>: \d<4>/

Is finite (albeit there are 63**8 * 10**4 == 2,481,557,802,675,210,000
combinations).  References to the heat death of the universe, anyone?

And then there's Unicode. %-/

In reality, I don't think it would be that useful.  Theoretically,
though, you *can* look inside the regex parse tree and create a
generator out of it... so, some module, somewhere.

> Now, just got to think of the syntax for it.. how to make it usable.

That's easy:

    use Regex::Generator;

    my @list is Regex::Generator(/a*/);
    for @list {
        dostuff($_)
    }

That or an iterator.

Luke

Reply via email to