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

Re: Transparent / Opaque references

Thread Previous | Thread Next
From:
Juerd
Date:
May 28, 2005 09:45
Subject:
Re: Transparent / Opaque references
Message ID:
20050528164544.GF31996@c4.convolution.nl
Thomas Sandlass skribis 2005-05-28 17:34 (+0200):
> >    %hash = { key => undef, foo => 'bar' };
> >    %hash<key> := $variable;
> >    %hash<key> = 5;  # $variable is now 5 too
> Sorry to interrupt, but wasn't {} not derefed when assigned
> to a % variable? Don't get me wrong, I like this meaning. And
> it seems to be intuitive once in a while ;)

You're right, {} there was wrong. I originally had $hash there, but
later realised using a ref was needlessly making the example more
complex.

> Why isn't \ good enough there? Because it requires $%hash<key> = 5?

Because transparent isn't opaque, and we need opaque, and the same
operator can'tbe used for both, and \ has always meant opaque, so it's
best to keep it that way and invent a new operator for the new feature,
keeping the existing operator for the existing feature.

> I propose %hash = { key => :\$variable, foo => 'bar' };

:\$variable looks like many things to me, but not an alias.

> Question: when a variable contains an opaque Ref and one
> uses this variable in an assignment as lhs, that still goes
> to the referee?

No. A reference ("opaque reference" in this thread) is a value.
Assignment throws away the old value.

We already have both opaque and transparent references, but jargon is
different: transparent references are called aliases and opaque
references are just called references.

> $var = 7;
> $ref = \$var;
> $$ref = 12; # should $ref suffice?

No, if you would use $ref, $ref itself would be 12, but $var not,
because the 12 would overwrite the reference in $ref.

> say $var; # prints 12
> $ref = 17; # detaches?

Yes.

> say $var; # still prints 12

Yes. 


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Thread Previous | 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