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

RE: Transparent / Opaque references

Thread Previous | Thread Next
From:
Thomas Sandlass
Date:
May 28, 2005 08:34
Subject:
RE: Transparent / Opaque references
Message ID:
8B2D97A317E8C9479E35FED99ADC3096CCC8C0@br2mex01.orthogon.com
Juerd wrote:
> The only real problem with having only infix := for binding, is that you
> can't easily use an alias (aka transparent reference) in a list. You can
> have an array of aliases, but it's harder to have an array or hash in
> which one element is an alias. Binding can be done explicitly:
>
>    %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 ;)


> But there is no way to set the transparent reference (aka alias)
> initially, because we lack a \-like syntax.

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

> So I propose that := becomes a prefix operator as well as an infix one,
> allowing:
>
>    %hash = { key => := $variable, foo => 'bar' };
>    %hash<key> = 5;  # $variable is now 5 too

I propose %hash = { key => :\$variable, foo => 'bar' };
Or should we also invent :=> to make a key/link pair?


Question: when a variable contains an opaque Ref and one
uses this variable in an assignment as lhs, that still goes
to the referee? How is the variable then detached? To wit:

$var = 7;

$ref = \$var;

$$ref = 12; # should $ref suffice?

say $var; # prints 12

$ref = 17; # detaches? Or is :\$ref = 17 needed? 

say $var; # still prints 12
-- 
TSa (Thomas SandlaƟ)


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