On Sat, Jul 01, 2006 at 03:04:05PM -0700, Matt Diephouse wrote: > Chip Salzenberg <[EMAIL PROTECTED]> wrote: > > .namespace # no key > >means the HLL root. > > That resolves the other ticket I opened yesterday (good). But I'd > prefer to have C< .namespace [] > so that we could also have the > matching C< find_global [], 'foo' >. Otherwise find_global becomes a > two step operation for finding globals in the root HLL namespace.
Well, that's a bit problematic. The [] syntax is inherited from the key syntax, and keys currently can't be empty. The use of keys is a hack, but it's a very convenient hack at the source code level, and unlikely to change. --- 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. If zero-length keys are not OK, then... --- PART 3, IN WHICH AN UGLY BUT WORKING HACK IS DESCRIBED -- I introduced a hack in my recent namespace cleanups. I was planning to ask/warn users about it, but then forgot I'd done it, so it's in the svn repo now. The hack is: When find_global or store_global expects a string or PMC to designate (name) a namespace, Parrot takes a null value to name the HLL root namespace. Thus: .sub main :main $P0 = find_global 'Foo', 'bar' $P0() .end .sub bar .end .namespace ['Foo'] .sub bar $P0 = find_global 'bar' # ['parrot';'Foo';'bar'] null $S0 $P1 = find_global $S0, 'bar' # ['parrot';'bar'] .end I don't recommend anyone coding anything to use this feature, because the more I look at it the less I like it: It's still a two-step process, and with kludge factor to boot. Zero-length keys are better, IMO. -- Chip Salzenberg <[EMAIL PROTECTED]>