Based on a conversation with Dan in IRC, it should be possible to interrogate PMCs about their generic type.
For example, tcl's [array exists varName] returns true if the variable is defined /and/ is an array variable (in perl-speak, a hash).
But, there's no easy way to ask a PMC, "are you hashlike?". So, for now, I have code like:
isnull the_array, array_no
typeof $I0, the_array
if $I0 != TclArray goto array_no
array_yes:
Which is fine if I'm self-contained, but not very nice for cross-language support.
Dan says:
09:37 <@Dan> Hrm. Post a bug to the list. We should collect up a list
of
properties that should be easily queryable
09:37 <@Dan> integer/float/string/invokable/hashlike/arraylike
09:37 <@Dan> Maybe some others too
> Based on a conversation with Dan in IRC, it should be possible to
> interrogate PMCs about their generic type.
> For example, tcl's [array exists varName] returns true if the variable
> is defined /and/ is an array variable (in perl-speak, a hash).
> But, there's no easy way to ask a PMC, "are you hashlike?".
Ha?
$ cat does.imc
.sub main @MAIN
$P0 = new Array
$I0 = does $P0, "array"
print $I0
$P1 = new PerlHash
$I0 = does $P1, "hash"
print $I0
print "\n"
$I0 = does $P1, "array"
print $I0
$I0 = does $P0, "hash"
print $I0
print "\n"
.end
$ ./parrot does.imc
11
00
leo
Closing call.