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

Re: Aliasing and Read-only variables

November 29, 2019 17:04
Re: Aliasing and Read-only variables
Message ID:
Dave Mitchell <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About