develooper Front page | perl.perl6.language | Postings from October 2008

[svn:perl6-synopsis] r14585 - doc/trunk/design/syn

Thread Next
From:
larry
Date:
October 1, 2008 12:54
Subject:
[svn:perl6-synopsis] r14585 - doc/trunk/design/syn
Message ID:
20081001195412.A249ECB9B0@x12.develooper.com
Author: larry
Date: Wed Oct  1 12:54:11 2008
New Revision: 14585

Modified:
   doc/trunk/design/syn/S03.pod

Log:
Revision to accumulator semantics so that -= dwims


Modified: doc/trunk/design/syn/S03.pod
==============================================================================
--- doc/trunk/design/syn/S03.pod	(original)
+++ doc/trunk/design/syn/S03.pod	Wed Oct  1 12:54:11 2008
@@ -3251,8 +3251,20 @@
 
 If you apply an assignment operator to a protoobject, it is assumed that
 you are implementing some kind of notional "reduction" to an accumulator
-variable.  To that end, the base operator is dropped and a simple
-assignment is done instead.  Hence you may correctly write:
+variable.  To that end, the operation is defined in terms
+of the corresponding reduction operator, where the protoobject
+becomes the operator's identify value.  So if you say:
+
+    $x -= 1;
+
+it is more or less equivalent to:
+
+    $x = [-]() unless defined $x;	# 0 for [-]()
+    $x = $x - 1;
+
+and $x ends up with -1 in it, as expected.
+
+Hence you may correctly write:
 
     my Num $prod;
     for @factors -> $f {

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About