I tried to index aggregates using several types of keys (that is,
several types of values), and it seems only string and integer values
can be used as keys. A quick look at the source in
compilers/imcc/symreg.c confirms this, there is no case for 'N' values
(and a test makes Parrot say build_key: unknown set).
Will it be possible to use floating points as keys for arrays? It's up
to the PMC to implement the indexing correctly, so support for this by
IMCC should be no problem, I think.
(I vaguely remember myself asking this sort of question before, quite
some time ago, but I couldn't find it anywhere in the mail archives --
sorry about that)
The reason for this question is LuaTable PMC, which can be used as both
an array as well as a Hashtable. I'd like to implement proper Lua Table
behaviour into the LuaTable PMC, but it should be able to cope with code
like this:
$P0 = new .LuaTable
$P1 = new .LuaNumber
$P1 = 42
$P0[1.234] = $P1
And this currently doesn't work, as mentioned above. (According to the
PDD on keys, it should be possible to do this:
op arg, P1[12.34] # Constant number key - handled as constant key
Kind regards,
klaas-jan
I am not sure how wise an idea this is given the difficult of
comparing floating point numbers for equality.
Matt
--
"Computer Science is merely the post-Turing Decline of Formal Systems Theory."
-Stan Kelly-Bootle, The Devil's DP Dictionary
You may be right, but nevertheless, that's the problem of the
language/pmc implementer (me, in this case). And, if Lua can do it, it
should be possible for me to do it as well.
klaas-jan
Amos Robinson
> Hi,
>
> I tried to index aggregates using several types of keys (that is,
> several types of values), and it seems only string and integer values
> can be used as keys. A quick look at the source in
> compilers/imcc/symreg.c confirms this, there is no case for 'N' values
> (and a test makes Parrot say build_key: unknown set).
As already expressed by Matt using floats as keys is a PITA. But you
can use arbitrary PMCs including Floats as a key by providing
appropriate compare and hash methods. See the new_*_x functions in
src/hash.c for examples to construct hashes with various key/value
types.
leo