Larry Wall wrote:

On Sun, Mar 13, 2005 at 01:15:52AM -0600, Rod Adams wrote:

: =item multi sub cos (?Num) returns Num
: : =item multi method Num::cos () returns Num


It would be nice if we could just say the first implies the second.
I guess what that effectively means is that even if you take the
default, it's only the value that's optional, not the type.  And,
in fact, you'd have to put the ? on the variable, not on the type,
so you might write those

   =item multi sub cos (Num ?$n = $CALLER::_) returns Num

instead.


Let me see if I'm following this correctly.

What you're saying is that when you do:

   my Foo $bar;
   $bar.baz(...);

Perl performs the following searches for baz():

   1) Foo and it's MMD table
   2) Foo's isas and roles
   3) Foo's AUTOMETH/AUTOLOAD
   4) Foo's isas' and roles' AUTOMETH/AUTOLOAD
   5) look in current scope for a &baz<Foo, ...>
   6) AUTOSUB/AUTOLOAD &baz<Foo, ...>

In case 5, you'd then be creating a temporary (sub lexical?) method that's a curried form of &baz<Foo, ...>, and then call it.

While that's a nice feature to have in general, I feel better about going ahead and predefining that the builtins are already members of Num, Str, Array, Hash for the shear performance and documentation values of it. And can't it be implemented as a straightforward:

multi sub cos (Num ?$x = $CALLER::_, Num|Str +$base) returns Num &Num::cos<> := &*cos<>.assuming:x($self)

hmm. Not sure about that currying there, since I'm trying to assume the invocant.

The other problem with case 5 is that the long name would be &cos<>, not &cos<Num>, since the first parameter is optional. So you'd have to expand the search beyond just the long name, which can get expensive.

hmm. I'm not sure I'm seeing all the pieces here.

-- Rod Adams.




Reply via email to