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

Keyed access to PerlArray/PerlHash

6 views
Skip to first unread message

Tom Hughes

unread,
Aug 12, 2002, 2:51:26 PM8/12/02
to perl6-i...@perl.org
Is indexing a PerlHash by an integer something that is supposed
to be valid? Likewise for indexing a PerlArray by a string?

Currently both of these are allowed, but as it stands my keyed
access patch breaks this. Obviously indexing either by a PerlScalar
will still work as the PerlScalar PMC will handle the type conversion
issues when necessary.

Tom

--
Tom Hughes (t...@compton.nu)
http://www.compton.nu/

Dan Sugalski

unread,
Aug 13, 2002, 2:16:12 AM8/13/02
to Tom Hughes, perl6-i...@perl.org
At 7:51 PM +0100 8/12/02, Tom Hughes wrote:
>Is indexing a PerlHash by an integer something that is supposed
>to be valid? Likewise for indexing a PerlArray by a string?
>
>Currently both of these are allowed, but as it stands my keyed
>access patch breaks this. Obviously indexing either by a PerlScalar
>will still work as the PerlScalar PMC will handle the type conversion
>issues when necessary.

Hash should support integer lookup. PerlHash doesn't have to, and may
throw an exception.

Arrays don't have to support lookup by string keys. They also can
throw an exception.
--
Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

Tom Hughes

unread,
Aug 13, 2002, 12:49:11 PM8/13/02
to perl6-i...@perl.org
In message <a05111b10b97e5445dbfe@[63.120.19.221]>
Dan Sugalski <d...@sidhe.org> wrote:

> Hash should support integer lookup. PerlHash doesn't have to, and may
> throw an exception.

I don't follow the logic behind this... Making it work for one but
not another is tricky - either get_integer on a Key PMC will work when
the key is a string or it won't.

In fact there isn't a Hash class at the moment, only a PerlHash.

Tom Hughes

unread,
Aug 13, 2002, 12:50:51 PM8/13/02
to perl6-i...@perl.org
In message <a05111b10b97e5445dbfe@[63.120.19.221]>
Dan Sugalski <d...@sidhe.org> wrote:

> Arrays don't have to support lookup by string keys. They also can
> throw an exception.

How about numeric keys? Presumably they can also throw an exception
as it doesn't make much sense to access the 5.2'th element of an array...

Dan Sugalski

unread,
Aug 13, 2002, 12:58:03 PM8/13/02
to Tom Hughes, perl6-i...@perl.org
At 5:50 PM +0100 8/13/02, Tom Hughes wrote:
>In message <a05111b10b97e5445dbfe@[63.120.19.221]>
> Dan Sugalski <d...@sidhe.org> wrote:
>
>> Arrays don't have to support lookup by string keys. They also can
>> throw an exception.
>
>How about numeric keys? Presumably they can also throw an exception
>as it doesn't make much sense to access the 5.2'th element of an array...

We'll just int() the result. I don't think checking is worth the time
it'll take.

Dan Sugalski

unread,
Aug 13, 2002, 12:56:44 PM8/13/02
to Tom Hughes, perl6-i...@perl.org
At 5:49 PM +0100 8/13/02, Tom Hughes wrote:
>In message <a05111b10b97e5445dbfe@[63.120.19.221]>
> Dan Sugalski <d...@sidhe.org> wrote:
>
>> Hash should support integer lookup. PerlHash doesn't have to, and may
>> throw an exception.
>
>I don't follow the logic behind this... Making it work for one but
>not another is tricky - either get_integer on a Key PMC will work when
>the key is a string or it won't.

Nobody's doing a get_integer on key PMCs--we're peeking directly.
(Integer lookup can also be done via the keyed_int method of the
vtable)

Basically we need to make sure that the hash we're using as a
scratchpad can be looked up by integer index for speed reasons. I
thought we'd split it out into a Hash class the way we'd done with
Array, but I guess not.

In that case, PerlHash should be able to be looked up by integer key
for now, and we'll see what we need to do to make things error out at
the language level.

Tom Hughes

unread,
Aug 13, 2002, 1:44:25 PM8/13/02
to perl6-i...@perl.org
In message <a05111b06b97eea0ca9c0@[63.120.19.221]>
Dan Sugalski <d...@sidhe.org> wrote:

> Nobody's doing a get_integer on key PMCs--we're peeking directly.
> (Integer lookup can also be done via the keyed_int method of the
> vtable)

At the moment it is using get_integer as I decided to get it all
working first (which it laregly is now) before optimising it.

However it's done it will still be shared code though as I don't
intend to duplicate key decipherment in all the classes that need
to do it.

> Basically we need to make sure that the hash we're using as a
> scratchpad can be looked up by integer index for speed reasons. I
> thought we'd split it out into a Hash class the way we'd done with
> Array, but I guess not.

Are you saying that integer lookup in hashes bypasses the hashing
and just knows where to look? If so then that isn't what integer
keys were doing - it was converting them to strings and then looking
them up in the normal way.

Dan Sugalski

unread,
Aug 13, 2002, 1:08:38 PM8/13/02
to Tom Hughes, perl6-i...@perl.org
On Tue, 13 Aug 2002, Tom Hughes wrote:

> In message <a05111b06b97eea0ca9c0@[63.120.19.221]>
> Dan Sugalski <d...@sidhe.org> wrote:
>
> > Nobody's doing a get_integer on key PMCs--we're peeking directly.
> > (Integer lookup can also be done via the keyed_int method of the
> > vtable)
>
> At the moment it is using get_integer as I decided to get it all
> working first (which it laregly is now) before optimising it.

We need to beef key.c and key.h up enough to have the direct access stuff
in there, so we don't need to use the vtables for keys.



> However it's done it will still be shared code though as I don't
> intend to duplicate key decipherment in all the classes that need
> to do it.
>
> > Basically we need to make sure that the hash we're using as a
> > scratchpad can be looked up by integer index for speed reasons. I
> > thought we'd split it out into a Hash class the way we'd done with
> > Array, but I guess not.
>
> Are you saying that integer lookup in hashes bypasses the hashing
> and just knows where to look? If so then that isn't what integer
> keys were doing - it was converting them to strings and then looking
> them up in the normal way.

Yes. This should be in the archive somewhere. (Apologies for being
brief--I'm on my way out for a few days)

Dan

0 new messages