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
> 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
> .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