Allison Randal <[EMAIL PROTECTED]> wrote:
Chip Salzenberg wrote:
>
>   --- PART 2, IN WHICH AN ELEGANT SOLUTION IS PROPOSED --
>
> On the other hand, we could extend the key PMC to represent emptiness,
> i.e. zero dimensions.  This seems useful for namespaces and could even prove
> useful for real keys.  And this makes keys even more compatible with the
> Array interface, which I think they might need to implement someday anyway.
>
> Allison, what do you think of zero-length keys, i.e. having [] construct a
> Key PMC describing no dimensions of lookup?  If we use those we can get rid
> of the current null-string hack.

Fundamentally altering the way keyed access works seems like a pretty
extreme solution when the problem is just "the root HLL namespace
doesn't have a name". (Actually, it does have a name: 'parrot', 'tcl',
'perl6', etc. A sort of "key who must not be named", if I won't be shot
for making terrible Harry Potter references at 1am.)

I don't think "fundamentally altering the way keyed access works" is a
fair description of what Chip proposed (and what I was asking for).
0-dimensional keys seem like a logical extension to multi-dimensional
keys, IMO.

Chip actually forgot that there is another way to get to the root HLL
namespace besides using the null string hack:

   $P0 = new .ResizablePMCArray # this can be any array type
   $P1 = get_namespace $P0

But arrays fill a different niche than keys do. Arrays are a runtime
solution and keys are a compile time solution. Writing out arrays when
you're writing code is painful and making keys at runtime is
impossible AFAICT.

So for the runtime (this is the HLL runtime, not the PIR runtime, btw)
we're all set. Arrays fill the need perfectly and let us access the
root HLL namespace. That makes me think that we don't need any new
opcodes.

It's just the compile time time -- the code that humans actually have
to write -- that is giving us trouble. That's a bit of a
simplification because in many cases compiler writers can optimize the
code and use keyed access in the output code, but it's just as simple
in that case to use any old hack.

That's why I was asking for C< $P0 = get_namespace [] > -- because I
actually have to write it. And I think it's a worthy goal to make
compiler writer's lives good.

Adding 0-dimensional keys would also let us get rid of the C<
.namespace > special case and replace it with C< .namespace [] >.

It's simpler to give the root HLL namespace a name.

I disagree on two counts here. First, I think C< [] > *is* a name.
Second, any solution which involves giving the HLL namespace a
different name will have to either (a) add new opcodes, (b) add more
code for all the other cases by making all referencing originate at
the root, or (c) add a special syntax, none of which is simple.

--
matt diephouse
http://matt.diephouse.com

Reply via email to