On Dec 10, 2003, at 12:37 AM, Luke Palmer wrote:
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.
Melvin pointed out another reason why this shouldn't actually conflict, but I'll also say: I would think that anonymous class wouldn't have names (pretty much by definition), not even generated ones. So to access class attributes of anonymous classes, you'd have to use something like:
$class1->get_attribute(".stuff")
I don't know what actual syntax Perl6 would use, but what I mean to say is that for an anonymous class you'd have to access anything about it via a reference to the class object, not via name (since it won't have one).
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 would think that we'd want to do it so that we don't have to do by-name lookups behind the scenes if we're not doing that up front. That is, I'd think that
$Foo::Bar::Baz::egg = 4;
would be doing a lookup to find the namespace "Foo::Bar::Baz" (may be hierarchical or not), and then a lookup of "egg" in that. But that:
package Foo::Bar::Baz
sub something { $egg = 4; }
would be able to do a more direct lookup. (That is, it would look up "egg" in the package namespace without having to go find the package namespace by name.)
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.
What do you mean by "tie" here? Are you talking about namespace aliasing, so that I can alias "Foo" to "A::B::C::D::E", so that I can say "Foo::bar" rather than "A::B::C::D::E::bar"? If so, it seems that this would work with or without a hierarchical structure. Definitely useful, though.
JEff