I am trying to understand the following small portion from S12, and it
seems slightly ambiguous to me:

======= from S12:
You may wish to declare an attribute that is hidden even from the
class; a completely private role attribute may be declared like this:

    C<my $!spleen;>

The name of such a private attribute is always considered lexically
scoped. If a role declares private lexical items, those items are
private to the role due to the nature of lexical scoping.
It's an attribute - thus it's per instance of the class(es) the role was composed into. The lexical stuff is just about the visibility of the attribute, not saying it's like a lexical variable in that it's one of them existing for the block (which isn't even true for blocks in general, since there can be closures).

I was unable to figure out what this piece of code would print:

role A {
        my $!spleen;
        method set_spleen($x) { $!spleen = $x; return self }
        method say_spleen() { say  $!spleen }

class B does A {}
class C does A {}


How many 3s will that print? Just a single 3 would indicate that every
instance of every class that composed A has its own copy. If 3 is
printed twice, that would indicate that not every instance but every
class has its own copy. All three 3s will indicate only a single copy
for the entire role.
I believe it would print one three. I expected this would work in Rakudo too - will look into why it doesn't.



Reply via email to