r29976 - docs/Perl6/Spec
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.pod2010-03-07 13:53:10 UTC (rev 29975) +++ docs/Perl6/Spec/S06-routines.pod2010-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. 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: + +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 or not, at the end of the C,
r29979 - docs/Perl6/Spec
Author: masak Date: 2010-03-07 16:40:03 +0100 (Sun, 07 Mar 2010) New Revision: 29979 Modified: docs/Perl6/Spec/S12-objects.pod Log: [S12] s/values/symbols/ Modified: docs/Perl6/Spec/S12-objects.pod === --- docs/Perl6/Spec/S12-objects.pod 2010-03-07 14:56:17 UTC (rev 29978) +++ docs/Perl6/Spec/S12-objects.pod 2010-03-07 15:40:03 UTC (rev 29979) @@ -1806,7 +1806,7 @@ try initializing an ordinary declaration using C<::=> to make a scoped readonly value.) -You may import enum types; only non-colliding values are imported. +You may import enum types; only non-colliding symbols are imported. Colliding enum keys are hidden and must be disambiguated with the type name. Any attempt to use the ambiguous name will result in a fatal compilation error. (All colliding values are hidden, not just the new one,
The silliness of max()
Please take a look at http://rt.perl.org/rt3/Ticket/Display.html?id=73356: rakudo: say max(1..5) rakudo c05478: OUTPUT«-Inf» * masak submits rakudobug for max(1..5) The weird thing is that it is right, according to the current spec. It says our multi max( Ordering @by, *...@values ) our multi max( Ordering $by, *...@values ) so the range 1..5 is actually bound to @by of the first candidate, leaving *...@values empty, and the default value of -Inf for a max() with no values seems to be quite OK. Of course this is not what the casual reader suspects. My proposed solution is to get rid of the sub form of max() entirely. Any objections? Cheers, Moritz -- Moritz Lenz http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/
Re: The silliness of max()
Moritz Lenz wrote: > Please take a look at http://rt.perl.org/rt3/Ticket/Display.html?id=73356: > > rakudo: say max(1..5) > rakudo c05478: OUTPUT«-Inf» > * masak submits rakudobug for max(1..5) > > The weird thing is that it is right, according to the current spec. It says > > our multi max( Ordering @by, �...@values ) > our multi max( Ordering $by, �...@values ) > > so the range 1..5 is actually bound to @by of the first candidate, > leaving *...@values empty, and the default value of -Inf for a max() with > no values seems to be quite OK. > > Of course this is not what the casual reader suspects. > My proposed solution is to get rid of the sub form of max() entirely. > Any objections? Why not just change the "by" parameter to be named instead of positional? Frankly, I don't understand why that isn't already the case. -- Jonathan "Dataweaver" Lang
Re: The silliness of max()
Jon Lang wrote: Moritz Lenz wrote: Please take a look at http://rt.perl.org/rt3/Ticket/Display.html?id=73356: rakudo: say max(1..5) rakudo c05478: OUTPUT«-Inf» * masak submits rakudobug for max(1..5) The weird thing is that it is right, according to the current spec. It says our multi max( Ordering @by, *...@values ) our multi max( Ordering $by, *...@values ) so the range 1..5 is actually bound to @by of the first candidate, leaving *...@values empty, and the default value of -Inf for a max() with no values seems to be quite OK. Of course this is not what the casual reader suspects. My proposed solution is to get rid of the sub form of max() entirely. Any objections? Why not just change the "by" parameter to be named instead of positional? Frankly, I don't understand why that isn't already the case. As Jon Lang says. Any ordered-concerning function needs to have an optional closure parameter if users are going to be able to sort values by an algorithm of their choice, and not just a single default one built-in to the type of the values being sorted. Moreover, "by" should be a named, optional parameter. Make @values into an ordinary Positional-doing parameter. Hmm ... "Ordering" ... I didn't notice the existence of that type before, and will have to look it up. Just from the above context I assume it is a closure having 2 main positional parameters and resulting in an Order value. -- Darren Duncan
Re: r29976 - docs/Perl6/Spec
On Mar 7, 2010, at 09:42 , pugs-comm...@feather.perl6.nl wrote: +has $!age is ref; # BUILD will automatically use ref binding, not copy Perl6 isn't done until it has reinvented Algol 68? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part