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 .()


  $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▀)

Reply via email to