Larry,

On Jul 21, 2005, at 8:07 PM, Larry Wall wrote:
On Thu, Jul 21, 2005 at 05:15:34PM -0400, Stevan Little wrote:
: This means that Roles are now first-class-ish things. Meaning they
: cannot just simply be composed into classes since now we have to keep a
: table of elements which are private to a Role.

Well, we've kinda been squinting at that issue from both ends for a
while now, and there's something in both views.

Yes, we have. One thing to consider is that it is much easier to get the "Role order doesn't matter" thing when they are composed. Once you start keeping the roles around, you run into the possiblity for such things as "next METHOD" being executed in Role context. I wont even speculate on what that should/could/would do, because I think we just shouldn't go there.

: On Jul 21, 2005, at 2:48 PM, Larry Wall wrote:
: > * All roles can write their shared attributes as $.x and not worry
: >  about whether the class declares them or not.
:
: I assume they need not worry because we can rely on conflict resolution
: to deal with most issues? Or are you thinking something different?

No, that's correct.  We've just basically said that $.x is now a method
call, and as long as you stick to that invocation syntax it just has
to be declared as a method somewhere in the parentage/role-age of
this object.  But collisions in $.x declaration will be treated as
collisions in method declaration.

So we really are looking at closure based access to attributes. This also means that the idea behind P6Opaque as a storage format is very different. In theory, we could implement these style classes in a very "Inside-Out" manner. In a way, we could look at:

has $.x is rw;

as being sugar for this (pseudo) Perl 6:

{
        my %x;
        $?CLASS.meta.add_method('x' => method ($self: ?$value) {
                %x{$self.id} = $value if $value.defined;
                %x{$self.id};
     });
}

Hmmm, it's a good thing I just got a book on CLOS metaobjects :)

: > * All roles can write completely private $x attributes that are not
: >  visible outside their lexical scope but are nevertheless
: >  per-instance.
:
: So the Role's scope is preserved here, as opposed to pushing $x into
: the classes scope. Correct?

My notion is that $x (the name proxy) is stored in the lexical scope
of the closure that just happens to be the closure for the role,
rather than keeping a name proxy in the package.  In either case,
$x or $.x is not a real variable, but a placeholder for a particular
slot in the object.  The actual proxy could be stored in the role's
package if that makes it easier to keep track of, but I'd like the
scoping of the name to be lexical like an "our" in that case.  But if
we can figure out how to store it more like a "my" variable but still
figure out which slot it maps to when instantiated, that might be cool.
Unfortunately, it could map to different slots in different objects,
so the class in question would have to keep track of where MyRole::('$x')
actually maps to.

It's certainly possible that this notion doesn't really map terribly
well onto roles.

Well, if we ditch the P6Opague type (as we currently know it) and use the Inside-Out method I show above. Then we just don't actually have class/instance attributes anymore at all. We really just have methods, some of which happen to be closures around per-instance values. Of course this means there is no direct access to attributes at all (which I think it not a bad thing, but I am into B&D like that).

Hmmm, I kind of like the smell of this.

: This would
: make it difficult to compose role methods into the method table without
: bringing along a lot of meta-info about from whence they came. It is
: doable I think, but adds some complexity for which I am not sure the
: cost outweighs the benefits.

Ok, I will respond to myself here:

No Stevan, that is silly, if it is closure-based Inside-Out thinga-mah-bobs, then we don't have to keep meta-context-info around, the closure does that for us. Duh!

But I like the $x/$.x distinction for classes, since it encourages
people to write completely private attributes to begin with, and
then maybe take the step of adding a dot when the want to provide
an accessor.

I agree, private should be encouraged.

*sniff* *sniff* this is smelling better and better :)

Stevan

Reply via email to