develooper Front page | perl.perl6.language | Postings from April 2005

Aliasing swapped values

Thread Next
April 10, 2005 10:48
Aliasing swapped values
Message ID:
Hi all,

Apologies if this has been covered.  What should this do?

  ($x,$y) := ($y,$x);

In Perl5:

  $x=2; $y=3;
  print "x: $x y: $y\n";
  (*::x, *::y) = (*::y, *::x);
  print "x: $x y: $y\n";
  print "x: $x y: $y\n";

This program shows typeglob aliasing.  If we try to alias swapped
value, we merely swap what they are pointing at and we haven't aliased
anything.  I am not sure this should be appropriate behavior for Perl6.
 Aliasing will be much more common in Perl6 so this will be a trap for
many.  In fact, consider this:

  ($c, $d) := ($y, $x);
  # later
  ($x,$y) := ($c, $d); # whoops!

That's going to confuse the heck out of people.  If we do as Perl5
does, we'll merely be swapping values since aliasing really doesn't
make much sense here, but that means for this case, ":=" == "=".


If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl --

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About