develooper Front page | perl.perl5.porters | Postings from October 2014

[perl #122947] [EXPERIMENT] Lvalue references

Thread Previous
From:
Father Chrysostomos via RT
Date:
October 15, 2014 00:36
Subject:
[perl #122947] [EXPERIMENT] Lvalue references
Message ID:
rt-4.0.18-19621-1413333401-570.122947-15-0@perl.org
On Tue Oct 14 08:18:57 2014, perl.p5p@rjbs.manxome.org wrote:
> * Father Chrysostomos via RT <perlbug-followup@perl.org> [2014-10-
> 14T09:45:31]
> > On Tue Oct 14 05:47:48 2014, perl.p5p@rjbs.manxome.org wrote:
> > > Since I haven't much played with it yet, I don't have much to say,
> > > except
> > > this: I think "lvalue reference" might need to be renamed.  My
> > > understanding is that it's always about the backslash on the left
> > > hand
> > > side, rather than having a reference in an lvalue.
> >
> > ‘Assigning to references’ is the least ambiguous way to refer to it
> > that I
> > can think.  How do we abbreviate that into a feature name?  If we
> > call it
> > refassign, it’s ambiguous again, because reference assignment would
> > be
> > assignment of references.
> 
> From the user's perspective, is there actually a reference involved in
> the left
> hand side?

Assignment has a return value, so yes.

(Hmm.  What should (\$x=\$y)=\$z do?  Currently it probably does not do what anyone expects.)

> The assignment forces \$left to refer to the same thing as
> \$right,
> but it doesn't in anyway [that I conceive of the phrase] assign to a
> reference.
> 
> Why not just "aliasing"?  The use of \ makes sense, and can (I think)
> be taught
> easily, but I think that actually calling it a lvalue reference or an
> assignment to a reference begins to confuse things that are distinct.

‘Aliasing’ would work.  Considering that the previous incarnation of this feature was Chip’s ‘bind’ operator, spelt := and inspired by Perl 6, maybe we could call this ‘bind’ or ‘binding’.  But the syntax is very different from Perl 6’s bind operator, so maybe that would be confusing.

For the record: When the bind operator was proposed, it was the difficulty in reconciling @a:=@b with @a:=[] and deciding when the rhs should automatically be dereferenced that led to \@a=\@b being preferred once more, as all the edge cases can be based on existing Perl 5 syntax that people already know.  ...In case you were wondering why I didn’t just borrow the Perl 6 := operator.  (This is from memory; I didn’t check the archives.)

-- 

Father Chrysostomos


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

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About