develooper Front page | perl.perl5.porters | Postings from November 2019

Re: Aliasing and Read-only variables

Thread Previous | Thread Next
From:
hv
Date:
November 29, 2019 17:04
Subject:
Re: Aliasing and Read-only variables
Message ID:
201911291656.xATGutP26811@crypt.org
Dave Mitchell <davem@iabyn.com> wrote:
:=head2 :ro
[...]
:then within the lexical scope of $x (from the point it's been introduced
:onwards), any lvalue-context usage of that variable is a compile-time
:error. Note that as well as forbidding all the obvious stuff like $x++,
:all the following would also be compile-time errors:
:
:    foo($x);
:    for ($x, ...) { ...}
:    $y = \$x;
:    sub foo: lvalue { ....; return $x }

I can imagine that being inconvenient. Is there an easy way to get an
unmodified temp copy of the value (for uses such as foo($x) or for (...))
without needing another variable? Modified temp copies are easy to get
with eg "$x" or 0+$x, but I don't offhand know of an easy way to get an
unmodified copy.

If we can make it convenient enough, I can see a lot of value in using
this to write more obviously functional code.

Hugo

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