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

Re: Transparent / Opaque references

Thread Previous | Thread Next
From:
=?ISO-8859-1?Q?=22TSa_=28Thomas_Sandla=DF=29=22?=
Date:
June 7, 2005 00:08
Subject:
Re: Transparent / Opaque references
Message ID:
42A547DF.3070401@orthogon.com
Juerd wrote:
>>$y() = 7;
> 
> No, sorry, that looks to me as if $y is a reference to an lvalue sub,
> not like any form of referencing of scalars.

I think it will come naturally to the C++ and Java folks. There the
accessor kind of functions is either mapped into the name get_y()
and set_y(value), or operator () is overloaded. In the latter idiom
assignment actually becomes $y(7). Which might be a bit far out for
Perlkind. But OTOH it looks like a function call...

This idiom looks better with scalar attributes of objects:

   $obj.attr() = 7; # parser supports to drop the .()

and

   $obj.attr(7); # beware, attr becomes 7 if the class of $obj works as such

And it nicely gives:

   $y = \$obj.attr;
   $y() = 7; # dereffed assignment
   $y = 13;  # detaches from $obj.attr
   say $obj.attr; # prints 7

I'm not sure but in Perl5 the equivalent to the second line above is

   $y-> = 7; # postfix -> is now spelled ()

isn't it?
-- 
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