# New Ticket Created by Zefram
# Please include the string: [perl #128842]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=128842 >
> sub ss0(Scalar $s, $nv) { my $v := $s; $v = $nv }
sub ss0 (Scalar $s, $nv) { #`(Sub|76872624) ... }
> my $a = 3
3
> ss0($a.VAR, 5)
5
> $a
5
> sub ss1($s, $nv) { my $v := $s; $v = $nv }
sub ss1 ($s, $nv) { #`(Sub|76873232) ... }
> ss1($a.VAR, 7)
Cannot assign to a readonly variable or a value
> $a
5
In the above, the := binding operator exhibits two very different
behaviours. In ss0() its effect is to set the container of its lhs to
be the value of its rhs. This is used to modify the value stored in
the container that was passed in as a parameter. In ss1() the same code
doesn't work. Based on behaviour I've seen from the binding operator in
other contexts, I think here its effect is to set the container of its
lhs to be the *container* of its rhs. The documentation doesn't admit to
this double meaning of the binding operator. doc/Language/operators.pod
describes only the second behaviour.
I would expect := to have consistent semantics, unaffected by parameter
type constraints. I'm not sure which semantic is intended. The first
is very useful, and needs to be available somehow. I have not found any
other way of accessing the content of a Scalar container from a reference
to the container, but maybe I missed something. The second semantic can
always be achieved in terms of the first, by adding an explicit ".VAR"
to the rhs. I have only ever wanted the first semantic, but I take no
position on Huffman coding.
-zefram