Author: larry Date: Wed Sep 13 11:05:34 2006 New Revision: 11977 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S03.pod doc/trunk/design/syn/S06.pod doc/trunk/design/syn/S09.pod doc/trunk/design/syn/S12.pod
Log: Metamethod revamp. Modified: doc/trunk/design/syn/S02.pod ============================================================================== --- doc/trunk/design/syn/S02.pod (original) +++ doc/trunk/design/syn/S02.pod Wed Sep 13 11:05:34 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 27 Aug 2006 + Last Modified: 13 Sept 2006 Number: 2 - Version: 66 + Version: 67 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -455,13 +455,11 @@ can speed it up.) Some object types can behave as value types. Every object can produce -a "safe key identifier" (C<SKID> for short) that uniquely identifies the +a "WHICH" value that uniquely identifies the object for hashing and other value-based comparisons. Normal objects just use their address in memory, but if a class wishes to behave as a -value type, it can define a C<.SKID> method that makes different objects +value type, it can define a C<.WHICH> method that makes different objects look like the same object if they happen to have the same contents. -SKID may also stand for "static key id", or "silly key id", or -"secret key id", or "supercalifragilisticexpialidocious key id". =item * @@ -483,13 +481,13 @@ =item * -Every object supports a C<META> function/method that returns the +Every object supports a C<HOW> function/method that returns the metaclass instance managing it, regardless of whether the object is defined: - 'x'.META.get_method_list; # get available methods for strings - Str.META.get_method_list; # same thing with the prototype object Str - META(Str).get_method_list; # same thing as function call + 'x'.HOW.get_method_list; # get available methods for strings + Str.HOW.get_method_list; # same thing with the prototype object Str + HOW(Str).get_method_list; # same thing as function call 'x'.get_method_list; # this is an error - not a meta object Str.get_method_list; # same thing Modified: doc/trunk/design/syn/S03.pod ============================================================================== --- doc/trunk/design/syn/S03.pod (original) +++ doc/trunk/design/syn/S03.pod Wed Sep 13 11:05:34 2006 @@ -14,7 +14,7 @@ Date: 8 Mar 2004 Last Modified: 13 Sep 2006 Number: 3 - Version: 62 + Version: 63 =head1 Changes to Perl 5 operators @@ -373,7 +373,7 @@ C<Array> objects, but it is true that C<@a === @a> because those are the same C<Array> object). -Any object type may pretend to be a value type by defining a C<.SKID> +Any object type may pretend to be a value type by defining a C<.WHICH> method which returns a value type that can be recursively compared using C<===>, or in cases where that is impractical, by overloading C<===> such that the comparison treats values consistently with their @@ -494,7 +494,7 @@ for ^(3,3) { ... } # (0,0)(0,1)(0,2)(1,0)(1,1)(1,2)(2,0)(2,1)(2,2) If applied to a type name, it indicates the metaclass instance instead, -so C<^Moose> is short for C<META(Moose)> or C<Moose.META>. It still kinda +so C<^Moose> is short for C<HOW(Moose)> or C<Moose.HOW>. It still kinda means "what is this thing's domain" in an abstract sort of way. =item * The C<...> operator is the "yada, yada, yada" list operator, @@ -512,7 +512,7 @@ variants C<.*>, C<.?>, and C<.+> to control how multiple related methods of the same name are handled. The C<.=> operator does inplace modification of the object on the left. The C<.^> operator calls a class metamethod; -C<foo.^bar> is short for C<foo.META.bar>. +C<foo.^bar> is short for C<foo.HOW.bar>. =item * Unary C<=> reads lines from a filehandle or filename, or iterates an iterator, or in general causes a scalar to explode its guts Modified: doc/trunk/design/syn/S06.pod ============================================================================== --- doc/trunk/design/syn/S06.pod (original) +++ doc/trunk/design/syn/S06.pod Wed Sep 13 11:05:34 2006 @@ -13,9 +13,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 21 Mar 2003 - Last Modified: 25 Aug 2006 + Last Modified: 13 Sept 2006 Number: 6 - Version: 53 + Version: 54 This document summarizes Apocalypse 6, which covers subroutines and the @@ -1358,7 +1358,7 @@ Objects with these types behave like values, i.e. C<$x === $y> is true if and only if their types and contents are identical (that is, if -C<$x.SKID> eqv C<$y.SKID>). +C<$x.WHICH> eqv C<$y.WHICH>). Bit Perl single bit (allows traits, aliasing, undef, etc.) Int Perl integer (allows Inf/NaN, arbitrary precision, etc.) @@ -1382,7 +1382,7 @@ =head2 Mutable types -Objects with these types have distinct C<.SKID> values that do not change +Objects with these types have distinct C<.WHICH> values that do not change even if the object's contents change. Array Perl array @@ -2038,10 +2038,10 @@ class LoudArray is Array { method TEMP { - print "Replacing $.SKID() at {caller.location}\n"; + print "Replacing $.WHICH() at {caller.location}\n"; my $restorer = $.SUPER::TEMP(); return { - print "Restoring $.SKID() at {caller.location}\n"; + print "Restoring $.WHICH() at {caller.location}\n"; $restorer(); }; } @@ -2097,7 +2097,7 @@ &old_thermo := &thermo; &thermo := sub ($t) { old_thermo( ($t-32)/1.8 ) } -Except that C<&thermo> is mutated in-place, so C<&thermo.SKID> stays the same +Except that C<&thermo> is mutated in-place, so C<&thermo.WHICH> stays the same after the C<.wrap>. The call to C<.wrap> returns a unique handle that can later be passed to @@ -2405,13 +2405,13 @@ So you may use C<sub> or C<hash> or C<pair> to disambiguate: - $ref = sub { 1, 2, 3, 4, 5, 6 }; # Anonymous sub returning list - $ref = { 1, 2, 3, 4, 5, 6 }; # Anonymous sub returning list - $ref = { 1=>2, 3=>4, 5=>6 }; # Anonymous hash - $ref = { 1=>2, 3, 4, 5, 6 }; # Anonymous hash - $ref = hash( 1, 2, 3, 4, 5, 6 ); # Anonymous hash - $ref = hash 1, 2, 3, 4, 5, 6 ; # Anonymous hash - $ref = { pair 1, 2, 3, 4, 5, 6 }; # Anonymous hash + $obj = sub { 1, 2, 3, 4, 5, 6 }; # Anonymous sub returning list + $obj = { 1, 2, 3, 4, 5, 6 }; # Anonymous sub returning list + $obj = { 1=>2, 3=>4, 5=>6 }; # Anonymous hash + $obj = { 1=>2, 3, 4, 5, 6 }; # Anonymous hash + $obj = hash( 1, 2, 3, 4, 5, 6 ); # Anonymous hash + $obj = hash 1, 2, 3, 4, 5, 6 ; # Anonymous hash + $obj = { pair 1, 2, 3, 4, 5, 6 }; # Anonymous hash =head2 Pairs as lvalues Modified: doc/trunk/design/syn/S09.pod ============================================================================== --- doc/trunk/design/syn/S09.pod (original) +++ doc/trunk/design/syn/S09.pod Wed Sep 13 11:05:34 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 13 Sep 2004 - Last Modified: 18 Aug 2006 + Last Modified: 13 Sept 2006 Number: 9 - Version: 13 + Version: 14 =head1 Overview @@ -772,7 +772,7 @@ my $val := %hash<foo><bar>; my @array; - my $ref = [EMAIL PROTECTED]; # $ref is a Capture object - see S02 + my $obj = [EMAIL PROTECTED]; # $obj is a Capture object - see S02 my %hash; %hash<foo><bar> = "foo"; # duh Modified: doc/trunk/design/syn/S12.pod ============================================================================== --- doc/trunk/design/syn/S12.pod (original) +++ doc/trunk/design/syn/S12.pod Wed Sep 13 11:05:34 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 27 Oct 2004 - Last Modified: 18 Aug 2006 + Last Modified: 13 Sept 2006 Number: 12 - Version: 21 + Version: 22 =head1 Overview @@ -34,7 +34,7 @@ that type can do. The class object is an Object, but it is not a Class, because there is no mandatory Class class in Perl 6. We wish to support both class-based and prototype-based OO programming. -So all metaprogramming is done through the current object's C<META> +So all metaprogramming is done through the current object's C<HOW> object, which can delegate metaprogramming to any metamodel it likes. However, by default, objects derived from Object support a fairly standard class-based model. @@ -120,19 +120,19 @@ 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<META> method. A "class" object is just considered an "empty" +C<HOW> method. A "class" object is just considered an "empty" instance in Perl 6, more properly called a "prototype" object. The actual class object is the metaclass object pointed to by the -C<META> syntax. So when you say "Dog", you're referring to both a +C<HOW> syntax. So when you say "Dog", you're referring to both a package and a prototype object, that latter of which points to the -actual object representing the class via C<META>. The prototype +actual object representing the class via C<HOW>. The prototype object differs from an instance object not by having a different type but rather in the extent to which it is defined. Some objects may tell you that they are defined, while others may tell you that they are undefined. That's up to the object, and depends on how the metaclass chooses to dispatch the .defined method. -The notation C<^Dog> is syntactic sugar for C<Dog.META>, 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. @@ -333,7 +333,7 @@ our $count; method ^count { return $count } -Such a I<metaclass method> is always delegated to the C<META> object just as methods like +Such a I<metaclass method> is always delegated to the C<HOW> object just as methods like C<.does> are, so it's possible to call this as C<Dog.count> or C<$dog.count>. However, best practice is probably to call such a class method as C<Dog.^count> or C<$dog.^count> to make it clear that it's in its own namespace separate @@ -1496,23 +1496,48 @@ =head1 Introspection -Every class has a C<META> function/method that lets you get at the +Metamethods for objects are named with interrogative pronouns in uppercase: + + WHAT the prototype object of the type, stringifies to short name + WHICH the object's identity value + WHO the package supporting the object, stringifies to long name + WHERE the memory address of the object + HOW the metaclass object: "Higher Order Workings" + WHEN (reserved for events?) + WHY (reserved for documentation?) + +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 +should use Perl 6's operators that make use of this information +implicitly. For instance, instead of + + $obj.WHAT eq 'Dog' + $x.WHICH === $y.WHICH + $obj.WHAT.bless(%args) + +you usually just want: + + $obj ~~ Dog + $x === $y + $obj.bless(%args) + +Every class has a C<HOW> function/method that lets you get at the class's metaobject, which lets you get at all the metadata properties for the class (or other metaobject protocol) implementing the objects of the class: MyClass.getmethods() # call MyClass's .getmethods method (error?) - MyClass.META.getmethods() # get the method list of MyClass + MyClass.HOW.getmethods() # get the method list of MyClass -The C<^> metasyntax is equivalent to .META: +The C<^> metasyntax is equivalent to .HOW: - MyClass.META.getmethods() # get the method list of MyClass + MyClass.HOW.getmethods() # get the method list of MyClass ^MyClass.getmethods() # get the method list of MyClass MyClass.^getmethods() # get the method list of MyClass -Each object of the class also has a C<.META> or C<.^> method: +Each object of the class also has a C<.HOW> or C<.^> method: - $obj.META.getmethods(); + $obj.HOW.getmethods(); $obj.^getmethods(); Class traits may include: @@ -1531,7 +1556,17 @@ disambig how to deal with ambiguous method names from roles layout P6opaque, P6hash, P5hash, P5array, PyDict, Cstruct, etc. -The C<.META.getmethods> method returns method-descriptors containing: +These are for the standard Perl 6 Meta-Object Protocol, but other MOPs +may define other traits. The identifier should probably be accessed +through the C<.WHO> object in any case, which may have its own object +methods depending on how type namespaces evolve over time. Which of +these items are actually part of the C<.HOW> object and which are +delegated back to the package and prototype objects is up to the MOP. +(Note also that anonymous classes may have anonymous packages and +prototype objects, in which case stringification is not likely to +produce something of interest to non-gurus.) + +The C<.HOW.getmethods> method returns method-descriptors containing: name the name of the method signature the parameters of the method @@ -1558,9 +1593,9 @@ Strictly speaking, metamethods like C<.isa()>, C<.does()>, and C<.can()> should be called through the meta object: - $obj.META.can("bark") - $obj.META.does(Dog) - $obj.META.isa(Mammal) + $obj.HOW.can("bark") + $obj.HOW.does(Dog) + $obj.HOW.isa(Mammal) But C<Object> gives you shortcuts to those, if you don't override them. @@ -1570,13 +1605,13 @@ actually calls: - $obj.META.does(Dog) + $obj.HOW.does(Dog) which is true if C<$obj> either "does" or "isa" C<Dog> (or "isa" something that "does" C<Dog>). Unlike in Perl 5 where C<.can> returns a single C<Code> object, -Perl 6's version of C<.META.can> returns a "WALK" iterator for a +Perl 6's version of C<.HOW.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 any class package's C<CANDO> method for names that are to be considered autoloadable methods