develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #109744] referenced constant loses readonlyness

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
July 31, 2013 15:55
Subject:
[perl #109744] referenced constant loses readonlyness
Message ID:
rt-3.6.HEAD-2552-1375286121-1437.109744-15-0@perl.org
On Wed Jul 31 02:42:52 2013, zefram@fysh.org wrote:
> Father Chrysostomos via RT wrote:
> >If $a+$b returns a value, not a variable, then we could say that \ and
> >for(...) and func(...) impose "variable context".
> 
> The usual term for this is "lvalue context".  A variable (that can vary)
> is an lvalue.  A read-only scalar is also an lvalue.
> 
> It is instructive to compare against C.  The C equivalent of Perl's \
> operator is &.  C's & operator requires that the operand be an lvalue
> (but not necessarily mutable), and it is a compile-time error to apply
> it to a non-lvalue.  Perl's pass-by-reference semantics would conflict
> with any attempt to prevent enreferencement of non-lvalues.
> 
> Are you going to document \'s variable-generating semantics?

I’m not sure how to go about that, nor do I think it is necessary.  I
always assumed that $a+$b would return a new mutable scalar, and that
\($a+$b) just references a scalar that would otherwise have been
short-lived.  Nothing in the observable behaviour contradicts that view.

This bare value vs variable distinction is not something that is
mentioned anywhere in the Perl documentation.  Is it something we want
to document rigidly, or will it just add to the mental burden?  Most of
the time it makes no difference.

In we want to put it anywhere, it should go under the documentation for
constants, wherever that might be, since that is where it actually
matters.  Apparently we don’t define the term ‘constant’ clearly anywhere.

One thing that makes this difficult is that constants are currently
inconsistent.  Making constants created by overload::constant and
constant.pm consistently return read-only scalars broke CPAN modules.

At this stage, I am willing to leave things inconsistent, as the changes
I have made so far have allowed me to fix the bugs I wanted to fix.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=109744

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