Author: larry Date: Thu Jul 10 14:01:39 2008 New Revision: 14560 Modified: doc/trunk/design/syn/S12.pod
Log: [S12] .HOW clarifications requested by ruoso++ Modified: doc/trunk/design/syn/S12.pod ============================================================================== --- doc/trunk/design/syn/S12.pod (original) +++ doc/trunk/design/syn/S12.pod Thu Jul 10 14:01:39 2008 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 27 Oct 2004 - Last Modified: 21 May 2008 + Last Modified: 10 Jul 2008 Number: 12 - Version: 59 + Version: 60 =head1 Overview @@ -120,7 +120,7 @@ Every object (including any class object) delegates to an instance of its metaclass. You can get at the metaclass of any object via the -C<HOW> method. A "class" object is just considered an "empty" +C<HOW> method, which returns an instance of the metaclass. A "class" object is just considered an "empty" instance in Perl 6, more properly called a "prototype" object, or just "protoobject". The actual class object is the metaclass object pointed to by the @@ -133,7 +133,7 @@ they are undefined. That's up to the object, and depends on how the metaclass chooses to dispatch the C<.defined> method. -The notation C<^Dog> is syntactic sugar for C<Dog.HOW>, so C<^> can be +The notation C<^Dog> is syntactic sugar for C<Dog.HOW()>, so C<^> can be considered the "class" sigil when you want to talk about the current metaclass instance. @@ -1871,8 +1871,11 @@ which also bypasses the macros. -For now Perl 6 reserves the right to change how all these macros and the -corresponding C<^> forms are defined in terms of each other. +For now Perl 6 reserves the right to change how all these macros +and the corresponding C<^> forms are defined in terms of each other. +In particular, the C<.^> forms will automatically supply the invocant +as the first argument to methods of the metaclass, while the other +forms require you to pass this explicitly. In general, use of these in ordinary code should be a red flag that Something Very Strange is going on. (Hence the allcaps.) Most code @@ -1895,17 +1898,17 @@ of the class: MyClass.methods() # call MyClass's .methods method (error?) - MyClass.HOW.methods() # get the method list of MyClass + MyClass.HOW.methods($obj) # get the method list of MyClass The C<^> metasyntax is equivalent to C<.HOW>: - MyClass.HOW.methods() # get the method list of MyClass - ^MyClass.methods() # get the method list of MyClass - MyClass.^methods() # get the method list of MyClass + MyClass.HOW.methods($obj) # get the method list of MyClass + ^MyClass.methods($obj) # get the method list of MyClass + MyClass.^methods() # get the method list of MyClass Each object of the class also has a C<.HOW> or C<.^> method: - $obj.HOW.methods(); + $obj.HOW.methods($obj); $obj.^methods(); Class traits may include: @@ -1934,7 +1937,7 @@ prototype objects, in which case stringification is not likely to produce something of interest to non-gurus.) -The C<.HOW.methods> method returns method-descriptors containing: +The C<.^methods> method returns method-descriptors containing: name the name of the method signature the parameters of the method @@ -1942,11 +1945,11 @@ multi whether duplicate names are allowed do the method body -The C<.methods> method has a selector parameter that lets you +The C<.^methods> method has a selector parameter that lets you specify whether you want to see a flattened or hierarchical view, whether you're interested in private methods, and so forth. -The C<.attributes> method returns a list of attribute descriptors +The C<.^attributes> method returns a list of attribute descriptors that have traits like these: name @@ -1961,9 +1964,9 @@ Strictly speaking, metamethods like C<.isa()>, C<.does()>, and C<.can()> should be called through the meta object: - $obj.HOW.can("bark") - $obj.HOW.does(Dog) - $obj.HOW.isa(Mammal) + $obj.HOW.can($obj, "bark") + $obj.HOW.does($obj, Dog) + $obj.HOW.isa($obj, Mammal) or @@ -1980,8 +1983,8 @@ These, may, of course, be overridden in a subclass, so don't use the short form unless you wish to allow for overrides. In general, C<Any> will delegate only those metamethods that read well when reasoning -about an individual object. Infrastructural methods like C<.methods> -and C<.attributes> are not delegated, so C<$obj.methods> fails. +about an individual object. Infrastructural methods like C<.^methods> +and C<.^attributes> are not delegated, so C<$obj.methods> fails. The smartmatch: @@ -1989,16 +1992,16 @@ actually calls: - $obj.HOW.does(Dog) + $obj.HOW.does($obj, Dog) which is true if C<$obj> either "does" or "isa" C<Dog> (or "isa" something that "does" C<Dog>). If C<Dog> is a subset, any additional C<where> constraints must also evaluate true. Unlike in Perl 5 where C<.can> returns a single C<Code> object, -Perl 6's version of C<.HOW.can> returns a "WALK" iterator for a +Perl 6's version of C<.^can> returns a "WALK" iterator for a set of routines that match the name, including all autoloaded and -wildcarded possibilities. In particular, C<.can> interrogates +wildcarded possibilities. In particular, C<.^can> interrogates any class package's C<CANDO> method for names that are to be considered autoloadable methods in the class, even if they haven't been declared yet. Role composition sometimes relies on this ability to determine whether a superclass supplies