Dan Sugalski writes:
> At 05:14 PM 12/5/2003 +0100, Leopold Toetsch wrote:
> >     set I2, P1["Foo\x00i"]   # I1 == I2
> >
> >gets currently the attribute idx (0) of "$Foo::i".
> >Q: Should the assembler mangle the "Foo::i" to "Foo\0i"
>
> I don't like it either, but the alternative is to impose an external 
> hierarchic structure. Which we certainly could do, though it may make 
> some things more difficult.
> 
> I'm more than willing to entertain arguments for and against the 
> hierarchic structure, but we're closing in on the point where we fix 
> the scheme and don't change it any more.

I'm not sure mangling is a good idea: think about anonymous classes.  If
we assign a name to each lexical class, then there are problems when one
instance of a class inherits from another instance of the same class.
That is:

    sub make_class(Class $parent) {
        return class is $parent {
            has $.stuff;
        }
    }

    my $class1 = make_class(Object);
    my $class2 = make_class($class1);

So, if you name that lexical class _class_0001 or something,
"_class_0001\0$.stuff" refers to both attributes.

If you generate a name for each instance of a lexical class, you're
setting yourself up for some major runtime cost -- concatenating the
class name to the attribute on each access (or memory cost if you want
to cache).

I think a heirarchy is a good idea for namespacing in general.  I've
always wanted to be able to tie namespaces in Perl 5.  It would only
make sense that if I tie Foo::, that Foo::anything:: would also go
through that tie to get the anything:: stash.

There are, of course, disadvantages.  It would be slower for cases where
$something::or::other are acessed a lot, as it's three lookups in the
absence of cache.  Also, it's not as easy to tell where a symbol table
entry came from.  I don't think either of these are major concerns, but
it depends on our ultimate goals.

I definitely want to tie namespaces though.

Luke

Reply via email to