--- Paul <ydbxmhc@yahoo.com> wrote:
>
> --- Luke Palmer <fibonaci@babylonia.flatirons.org> wrote:
> > > Ok, this is strange to me.
> > > multi handle_event ($window, $event: $mode) {...} # two
> invocants
> > > Does that mean I can assume $event is a valid object of some
> sort?
> >
> > Yep.
> > multi handle_event ($window, Undef $event: $mode) {...}
> > Then you would get a valid undef object. :)
>
> okay....and why would I want that?
>
> > > .stuff()
> > > is still going to default to $window, right?
> >
> > Yes. $_ binds to the first invocant.
>
> Okay, that makes expected sense....
>
> > > Or is that saying that if there is no $window.stuff() it'll look
> > > for $event.stuff() ?
> >
> > No. If there's no $window.stuff, you'll get an error.
>
> Okay, but I thought the main point of multimethods was that it could
> be
> redefined and would be dynamically dispatched to the correct version
> based on the invocant and/or arguments, i.e., the signature.
>
> What, exactly, is the value of calling multiple arguments to one
> method
> call "invocants"? I'm *really* missing something, here.....
>
The multidispatch is done on the invocants, only.
multi infix:= (Int $i: String $s) {...}
multi infix:= (Float $f: String $s) {...}
If you say
my Int $j;
$j = "foobar";
The dispatch will chase down the (Int/String) version.
If you say:
$j = new Dog("Spot");
The dispatcher will NOT look for an (Int/Dog) signature. Instead, it
will either blow up, or invoke Dog("Spot").toString -- I'm not sure
which.
=Austin
Thread Previous
|
Thread Next