HaloO Juerd,
you wrote:
Thomas Sandlaß skribis 2005-04-01 23:37 (+0200):So you expect $bar to contain value 2 and detach from $foo?
No. But if you said $baz instead of $bar, then yes.
Ohh sorry, I mis-read your mail as talking about chains of references: $baz to $bar to $foo to 2. The last step could also be direct storage. Then my question was if an assignment is forwarded along this chain or if a ref is somehow manipulating it's target directly. Consider:
my $one = 1; my $two := $one; my $three = \$two; # same as := ? was actually your question, or not? my $four := three; my $five = 5;
$four = 4; # $one == 4 now? $$four := $five;
say $three; # prints 5?
then why are values mutable, do scalars not have three different sigils and do things automatically convert without the intervention of lists?
Values are immutable in the abstract. That means 3 is always 3. Only variables change (reference to) value, hence the name. An object that is not referenced and objects that just reference each other are garbage collected! For simple values the reference is optimised into direct storage if possible. These two things are the implementation of conceptually immutable values.
By introducing a finite
subtype Example of Array where { is shape(0..9) of Bool };
you have 1024 possible immutable values which could be pre-allocated and then referenced as needed. For less restricted types you get so many possible values that other implementation strategies are needed :) Calling a method through a variable conceptually produces a new value of the object type in question which in turn is implemented by changing the object in place for practical reasons.
If =:= tests variable sameness, then it should do that literally in order to both be useful and look like :=. For reference equality you can still use \FOO == \BAR (I assume).
In my view of the world =:= checks for identity of values. Equality could hold for non-identical objects. E.g. a complex number object with imaginary part 0 could be considered equal to a real number with the value of the real part of the complex number:
my Complex $complex = (3.2, 0); my Num $real = 3.2;
$complex =:= $real # false $complex == $real # true
The above would of course be implemented by installing apropriate multis for &infix:<==> from the Complex class. Overloading =:= OTOH will be hardly necessary nor usefull. -- TSa (Thomas Sandlaß)