Author: lwall
Date: 2010-03-07 15:42:59 +0100 (Sun, 07 Mar 2010)
New Revision: 29976

Modified:
   docs/Perl6/Spec/S06-routines.pod
   docs/Perl6/Spec/S12-objects.pod
Log:
[S06,S12] make attributive parameters default to 'is copy' binding
make easy way for an attribute to override this with 'is ref'


Modified: docs/Perl6/Spec/S06-routines.pod
===================================================================
--- docs/Perl6/Spec/S06-routines.pod    2010-03-07 13:53:10 UTC (rev 29975)
+++ docs/Perl6/Spec/S06-routines.pod    2010-03-07 14:42:59 UTC (rev 29976)
@@ -16,8 +16,8 @@
 
     Created: 21 Mar 2003
 
-    Last Modified: 9 Feb 2010
-    Version: 128
+    Last Modified: 7 Mar 2010
+    Version: 129
 
 This document summarizes Apocalypse 6, which covers subroutines and the
 new type system.
@@ -1543,7 +1543,7 @@
 
     submethod initialize($.name, $!age) {}
 
-then the argument is assigned directly to the object's attribute of the
+then the argument is bound directly to the object's attribute of the
 same name. This avoids the frequent need to write code like:
 
     submethod initialize($name, $age) {
@@ -1551,6 +1551,22 @@
         $!age  = $age;
     }
 
+The initialization of attributes requires special care to preserve
+encapsulation; therefore the default for attributive parameters is
+value semantics, that is, as if specified with C<is copy>.  Hence,
+the submethod above is really more like:
+
+    submethod initialize($name is copy, $age is copy) {
+        $.name := $name;      # or maybe = here, since it's a parent's attr
+        $!age  := $age;       # or maybe only $! parameters work really
+    }
+
+If you wish to allow the user to initialize an attribute by reference,
+you may either write your own initializer submethod explicitly, or
+simply mark the attributes you want to work that way with C<is ref>:
+
+    has $!age is ref;   # BUILD will automatically use ref binding, not copy
+
 To rename an attribute parameter you can use the explicit pair form:
 
     submethod initialize(:moniker($.name), :youth($!age)) {}

Modified: docs/Perl6/Spec/S12-objects.pod
===================================================================
--- docs/Perl6/Spec/S12-objects.pod     2010-03-07 13:53:10 UTC (rev 29975)
+++ docs/Perl6/Spec/S12-objects.pod     2010-03-07 14:42:59 UTC (rev 29976)
@@ -13,8 +13,8 @@
 
     Created: 27 Oct 2004
 
-    Last Modified: 24 Jan 2010
-    Version: 98
+    Last Modified: 7 Mar 2010
+    Version: 99
 
 =head1 Overview
 
@@ -796,9 +796,9 @@
 
 is equivalent to
 
-    submethod BUILD ($tail, $legs) {
-        $!tail = $tail;
-        $!legs = $legs;
+    submethod BUILD ($tail is copy, $legs is copy) {
+        $!tail := $tail;
+        $!legs := $legs;
     }
 
 Whether you write your own C<BUILD> or not, at the end of the C<BUILD>,

Reply via email to