Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binding operators and related introspection

1 view
Skip to first unread message

Darren Duncan

unread,
Jul 15, 2006, 6:12:25 PM7/15/06
to perl6-l...@perl.org
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

Sam Vilain

unread,
Jul 17, 2006, 5:36:14 PM7/17/06
to Darren Duncan, perl6-l...@perl.org
Darren Duncan wrote:
> 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.
> [...]

> 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'
>

Maybe we need ruby's Object.all or whatever it is. Then you can write
something like

Object.all.grep:{ $_ =:= $z }.map{ $_ := $y };

Sam.


0 new messages