On 9/3/05, Stuart Cook <[EMAIL PROTECTED]> wrote: > On 03/09/05, Yuval Kogman <[EMAIL PROTECTED]> wrote: > > A multi sub is a collection of variants, so it doesn't have arity, > > each variant has arity. > > > > I'd say it 'fail's. > > But if the reason you're calling `&foo.arity` is to answer the > question "Can I call this sub with three arguments?" then that kind of > behaviour isn't going to help very much. > > Which leads me to believe that instead of writing > > if &foo.arity == 3 { ... } > > you should probably be writing something like this: > > if &foo.accepts(3) { ... }
That's a nice reformulation. However, .arity is still important. But maybe .arity doesn't exist, and all you get are .accepts, .min_arity, and .max_arity. After all, "for" has to know how many things to take off of the list, and doing: my @pass; given ({ &foo.accepts($_) }) { when 1 { @pass = @args.shift(0,1) } when 2 { @pass = @args.splice(0,2) } ... } Is unacceptable. But *the* arity of a function in Perl is rather ill-defined. (As a matter of fact, I use the existence numeric casing to determine when a language is not general enough in a particular area; C++ had to do numeric casing to implement typelists, Haskell has to do numeric casing to implement variadic functions and lifts, etc. So far, I've never had to do it in Perl. :-) Luke