On 08/21/2011 06:00 AM, Darren Duncan wrote: > Patrick R. Michaud wrote: >> On Sat, Aug 20, 2011 at 04:41:08PM -0700, Darren Duncan wrote: >>> I believe the general solution to this problem is to make all >>> objects immutable, with the only exception being explicit >>> references, and so mutating an object isn't an option; rather you >>> have to derive a new object. >>> >>> "Values" of all types should be immutable, even if that type is >>> Array or whatever, and only "Variables" should be mutable. >>> ... >> >> To make sure I understand correctly, you're essentially >> saying that @a.push(3) should not modify @a directly -- someone >> would have to write something like >> >> @a = @a.push(3) # or @a .= push(3) >> >> And to do a "shift", one would have to do something like >> ($value, @a) = @a; >> since @a.shift would be unable to mutate the array. (I'm not >> exactly sure what pop would look like.) >> >> Is that correct? > > Yes, that's what I'm saying. > > And we've already been making moves in that direction.
Moving into the direction of immutability doesn't help with the problem at hand -- it only helps here if we force everything(*) to be immutable, or at least encapsulating every mutable object into special types, like Monads in Haskell. (*) ok, not everything, but everything that can be stored in an object And I'd be very disappointed if Perl 6 turned into Haskell so late in its development stage (remember that we have working compilers, a growing number of modules and active users), especially since it's not tailored to be a language that is tailored towards immutability. Cheers, Moritz