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

[perl #109744] referenced constant loses readonlyness

Thread Previous | Thread Next
Father Chrysostomos via RT
July 31, 2013 15:55
[perl #109744] referenced constant loses readonlyness
Message ID:
On Wed Jul 31 02:42:52 2013, 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 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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About