Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A6: Assignment Overloading

6 views
Skip to first unread message

Luke Palmer

unread,
Mar 13, 2003, 3:35:25 AM3/13/03
to perl6-l...@perl.org
So, now that we have binding, is it possible to overload the
assignment operator? Does the assignment operator mean "value copy"
instead of "reference copy"?

Luke

Damian Conway

unread,
Mar 13, 2003, 9:20:28 PM3/13/03
to perl6-l...@perl.org
Luke Palmer wrote:

> So, now that we have binding, is it possible to overload the
> assignment operator?

Not really. The problem is that C<&infix:=> is really an operator on
*containers*, not on *values*. So, in order to overload C<=>, you'll still
need to define an appropriate C<STORE> method on the appropriate
implementation class for the container. Whether C<STORE> can also be spelled
C<&infix:=> is another question.


> Does the assignment operator mean "value copy"
> instead of "reference copy"?

The assignment operator means copy rhs's value into lhs's container.
The binding operator means copy (reference to) rhs's container into lhs's
symbol table entry.

Damian


Larry Wall

unread,
Mar 14, 2003, 2:00:51 PM3/14/03
to perl6-l...@perl.org

Note that assignment is a very shallow copy in any event. Intrinsic types
are copied by default, plus any objects with a .copy method. In other words,
Scalar has a .copy method by default, and anything else is your own doing.
Int, Num, Str, and Ref inherit the .copy interface from Scalar. In particular,
a Ref only copies itself unless it refers to something with a .copy method.

In other words, the .copy method defines it as an intrinsic scalar type.

That's exactly how it works, bearing in mind that any or all of the
details might be wrong.

Larry

0 new messages