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

Q: Keys can be strings/ints only?

0 views
Skip to first unread message

Klaas-Jan Stol

unread,
Jan 20, 2006, 3:34:55 PM1/20/06
to perl6-i...@perl.org
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).

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

Matt Fowles

unread,
Jan 20, 2006, 3:54:03 PM1/20/06
to Klaas-Jan Stol, perl6-i...@perl.org
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

Klaas-Jan Stol

unread,
Jan 20, 2006, 3:57:27 PM1/20/06
to Matt Fowles, perl6-i...@perl.org
Matt Fowles wrote:

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

unread,
Jan 21, 2006, 12:35:58 AM1/21/06
to perl6-i...@perl.org
I think I remember reading one of the comments in the IMCC compiler
something to the effect of "if someone needs N keys they can just
convert to strings."
Sorry I can't find the exact wording right now, but it might point you
somewhere useful.

Amos Robinson

Leopold Toetsch

unread,
Jan 21, 2006, 7:33:55 AM1/21/06
to Klaas-Jan Stol, perl6-i...@perl.org

On Jan 20, 2006, at 21:34, Klaas-Jan Stol wrote:

> 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

0 new messages