On Fri, Jan 13, 2006 at 11:42:13PM +0000, Luke Palmer wrote:
: 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.

That doesn't seem sufficiently general.  I'd rather see some context
that can apply a signature to the head of a list and treat the
"unslurped" part as unmatched.  Maybe a "for" loop could be taught
to supply such a context, or a "when".  Or maybe it's just the result
of embedding a sig inside a rule, or of matching a sig using ~~.

Basically, we just have to find a way to treat the sig as a pattern
that isn't anchored at the end.

Larry

Reply via email to