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

Variadic Multi-Dispatch (or, M-D on certain invocants only)

5 views
Skip to first unread message

Chromatic

unread,
May 14, 2006, 3:22:24 AM5/14/06
to Perl 6 Internals
Hi there,

I have a spot in Pheme where I'd like to use multi-dispatch on only the first
argument to a function. The function itself is slurpy. That is:

.sub some_function :multi( Array )
.param pmc args
# ...
.end

.sub some_function :multi( string )
.param string first_arg
.param pmc args :slurpy
# ...
.end

I can't seem to get this to work. I'm ambivalent whether the right approach
is to require a special "maybe variadic" marker in the multi param list or to
say that any multi params are the only dispatchable invocants and let the
remaining params, if any, go unchecked.

Another approach is fine too.

Now I probably *should* handle this elsewhere in the Pheme compiler, but it
seems like an issue that may come up in other places.

-- c

Leopold Toetsch

unread,
May 14, 2006, 4:33:53 AM5/14/06
to chromatic, Perl 6 Internals

On May 14, 2006, at 9:22, chromatic wrote:

> I have a spot in Pheme where I'd like to use multi-dispatch on only
> the first
> argument to a function. The function itself is slurpy. That is:

Completing your example:

.sub some_function :multi( Array )
.param pmc args

print "array\n"
.end

.sub some_function :multi( string )
.param string first_arg
.param pmc args :slurpy

print "string\n"
.end
.sub main :main
.local pmc a
a = new .Array
some_function(a)
some_function("xx", a)
.end

$ ./parrot md.pir
array
string

... I don't see a problem.
leo

Chromatic

unread,
May 14, 2006, 5:19:18 PM5/14/06
to Leopold Toetsch, Perl 6 Internals
On Sunday 14 May 2006 01:33, Leopold Toetsch wrote:

> .sub some_function :multi( Array )
> .param pmc args
> print "array\n"
> .end
>
> .sub some_function :multi( string )
> .param string first_arg
> .param pmc args :slurpy
> print "string\n"
> .end
> .sub main :main
> .local pmc a
> a = new .Array
> some_function(a)
> some_function("xx", a)
> .end
>
> $ ./parrot md.pir
> array
> string
>
> ... I don't see a problem.

Hm, I was using 'array' as the type and expecting it to pick up
ResizablePMCArray and ResizableStringArray too. After fixing that, things
work.

Thanks!

-- c

0 new messages