Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dispatch on context

4 views
Skip to first unread message

Luke Palmer

unread,
Sep 8, 2003, 4:38:32 AM9/8/03
to Piers Cawley, perl6-l...@perl.org
Piers Cawley writes:
> So, I was wondering about how to do multidispatch based on the
> context in which something is called, which leads me to wonder if
> there's going to be a way of reifying calling context so I could
> write:
>
> method whatever($arg1, $arg2)
> { my multi whatever ($self, Scalar $context:
> $arg1, $arg2) { ... }
> my multi whatever ($self, Array $context:
> $arg1, $arg2) { ... }
> whatever($_, want(), $arg1, $arg2) }

The way I see that happening is if we allow certain kinds of constants
in multi declarations.

my multi whatever ($self, Class $context is derived(Scalar):
$arg1, $arg2) {...}

That'd be nice in a number of different ways. Without this special
feature, an enabling level of indirection can be added with
parameterized types:

my class ClassVal [Class $TYPE] {
# Does nothing, and may even be optimized away
}
my multi whatever ($self, ClassVal[Scalar] $context:
$arg1, $arg2) {...}
# ...

whatever($_, ClassVal[want], $arg1, $arg2);
# ^ does a : go here?

That doesn't handle inheritance correctly, but it can be made to,
provided proper introspection into $TYPE.

Luke

Piers Cawley

unread,
Sep 8, 2003, 4:20:42 AM9/8/03
to perl6-l...@perl.org
So, I was wondering about how to do multidispatch based on the
context in which something is called, which leads me to wonder if
there's going to be a way of reifying calling context so I could
write:

method whatever($arg1, $arg2)
{ my multi whatever ($self, Scalar $context:
$arg1, $arg2) { ... }
my multi whatever ($self, Array $context:
$arg1, $arg2) { ... }
whatever($_, want(), $arg1, $arg2) }

Just wondering.


0 new messages