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

Aliasing swapped values

Thread Next
From:
Ovid
Date:
April 10, 2005 10:48
Subject:
Aliasing swapped values
Message ID:
20050410174751.88219.qmail@web60805.mail.yahoo.com
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);
  $y=4;
  print "x: $x y: $y\n";
  $x=5;
  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, ":=" == "=".

Cheers,
Ovid

-- 
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 -- http://users.easystreet.com/ovid/cgi_course/

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