On 1/13/06, Dave Whipp <[EMAIL PROTECTED]> wrote:
> What happens if I simply abandon the attempt at anonymous MMD and use a
> named multi-sub, instead:
>
> {
>    my multi sub process_arg("-f", Str $f is rw) {
>       $f .= absolute_filename
>    }
>    my multi sub process_arg("--quux", Str arg1, Str arg2) { ... }
>    ...
>    my multi sub process_arg(Str _) {} # skip unrecognised args
>
>    for @*ARGV: &process_arg;
> }

Oh, that's a clever way to process arguments.  A module could probably
turn that into a nice declarative option parsing library.

Unfortuately, it the form you've written above, that doesn't work. 
That's because process_arg does not have a well-defined arity, so
"for" doesn't know how many elements to pull of the list each time. 
In order to do that correctly, there would have to be some very fine
communication between for and the signature pattern matcher.

I could definitely see a library doing this though:

    getopts @*ARGV,
        -> '-f', Str $f is rw {...},
        -> '--quux', Str $arg1, Str $arg2 {...},
        -> $ { };  # ignore

It is likely doable without any magic too wicked, too.

Luke

Reply via email to