develooper Front page | perl.perl6.language | Postings from July 2006

binding operators and related introspection

Thread Next
Darren Duncan
July 15, 2006 15:13
binding operators and related introspection
Message ID:
After confirming between Synopsis 3 and the newest Pugs that the 
binding operator := works as follows ...

   my $x = 'foo';
   my $y = 'bar';
   my $z := $x;    # $x and $z point to same 'foo', $y to a 'bar'
   $z := $y;       # $y and $z point to the same 'bar', $x to a 'foo'
   print "x,y,z are '$x','$y','$z'\n"; # output: x,y,z are 'foo','bar','bar'

That makes sense of course, and is what people would want most of the time.

But I would also like to have an easy way to change all bindings to 
the same variable at once to point to the same new variable. 
Essentially an easy way for us to implement ourselves the run-time 
folding that I raised in the "optimizing with === immutable 
comparitor" thread.  I would like for this to work:

   my $x = 'foo';
   my $y = 'bar';
   my $z := $x;    # $x and $z point to same 'foo', $y to a 'bar'
   $z.rebind_all_aliases_to( $y ); # $x and $y and $z all point to 'bar'

Alternately or in addition to the last line, if something like this could work:

   for $z.aliases -> $z_alias {
     $z_alias := $y;
   # now $x and $y and $z all point to 'bar'

Unless something like this could be available for use, it would be 
impractical to implement run time folding just using := since we 
could end up in a tug of war situation if folding comparisons between 
pairs drawn from a pool of all equal elements were not done in 
exactly the right sequence.

-- Darren Duncan

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