--- Dan Sugalski <[EMAIL PROTECTED]> wrote:
> At 7:30 AM +0000 1/24/03, Piers Cawley wrote:
> >In my quest to eliminate as many explicit conditionals from my code
> as
> >possible, I found myself wondering if Perl 6's multidispatch
> mechanism
> >would allow one to write:
>
> Okay, I think I remembered the problem. Assume the following:
>
> list bar(int); # bar takes an int, returns a list
> scalar bar(int); # bar takes an int, returns a scalar
>
> and also assume the following:
>
> xyzzy(scalar); # xyzzy takes a scalar
> xyzzy(list); # xyzzy takes a list
>
> and then we make the call:
>
> xyzzy(bar(1));
>
> Which bar do we call? And which xyzzy?
In theory, if there's a return type expected, we could use that as the
final arbiter.
If not, but "if it looks like a scalar" ...
xyzzy(bar 1); # Scalar
xyzzy(bar(1)); # Scalar
xyzzy(bar((1))); # List?
xyzzy(bar(list(1))); #List
xyzzy(bar(scalar(1))); # Scalar
Optionally, we whinge about "ambiguous method invocation at line ..."
and punt; requiring the user to cast or establish context.
Welcome to namespace hell. Woo-hoo! It's just like the C++, only with
one more dimension to consider.
=Austin