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

Re: How to define a new value type?

Thread Previous | Thread Next
From:
John M. Dlugosz
Date:
September 16, 2008 17:53
Subject:
Re: How to define a new value type?
Message ID:
20345-70153@sneakemail.com
Stéphane Payrard cognominal-at-gmail.com |Perl 6| wrote:
> I don't understand how = differs with that semantic from :=
> I would expect that = would make a copy (clone?) of the object.
> For a mutable object, I don't know if that copy should be immediate or deffered
> by a mechanism of copy on write. Probably that behavior could depend on a
> trait of the class that implements to be copied object.
>
>   

Not the best illustration, but the only one I have prepared so far:
<http://www.dlugosz.com/Perl6/web/assignment/assign-1.png>

This shows $x = $y;.

The use of := (binding) would affect the leftmost column. 

   my $z := $y;

would have $z's symbol table entry point to the same Item as $y, namely 
#8CD9.

Assignment (=) does not clone or copy the object.  In the illustration, 
note that both Items refer to the same Dog (#A829) after assignment.  
With reference assignment semantics, if you want a copy or clone, you 
make one as an explicit step.  Hence the existence of methods like 
deepcopy in the base Object of languages with that feature.

The copy-on-write behavior you suggest is what Perl 5 does to make 
operator overloading appear to have value semantics.  But Perl 6 does 
not describe this mechanism in any way.  Instead, "value types" are 
immutable so it doesn't matter that the object is not cloned.

--John

Thread Previous | 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