Jon Lang dataweaver-at-gmail.com |Perl 6| wrote:
John M. Dlugosz wrote:
 And you can use CLASS in a role also, confidant that it will be looked up
according to the normal rules when the class is composed using that role,
just like any other symbol that is not found when the role is defined.
Using ::?CLASS in a role is an error (unless you mean the class surrounding
this role's definition, in which case it is a warning).

Can a role inherit from a class?  If so, to which class does CLASS
refer: the inherited one, or the one into which the role is composed?

If you have an "is Base" item in a role, that will apply the inheritance to the composited class when it is used. Whether the role itself inherits depends on how you think about it.

In all cases, CLASS will refer to a virtual symbol that becomes the most-derived (complete) class at run time. In an object, CLASS refers to the final dynamic type. It is virtual. For my treatment of the subject, see my "spec doc" at <http://www.dlugosz.com/Perl6/>, section 12.5.1 "Class names used in methods". I'd be happy to talk more about it in-depth. Also check the mailing list for the discussion "Class names are virtual" starting on the 20th:

Larry, you've wanted to have class names used within a class be virtual. With various degrees of conviction across the synopses, you've wanted classes defined within a class to be overridable, or all classes referenced by a class to be overridable, speculating on whether this is do-able.
...
You'll be happy to know that not only is it do-able (once you know what is and is not affected), but it will play a role in making the type system F-bounds quantified.


--John

Reply via email to