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

allow .re and .im to be l-values

2 views
Skip to first unread message

Siddhant Saraf

unread,
May 19, 2012, 12:05:26 AM5/19/12
to perl6-l...@perl.org
<sisar> r: my $x = 4 + 2i; $x.re = 5;
<p6eval> rakudo 45679a: OUTPUT«Cannot assign to a non-container␤ in
block <anon> at /tmp/PeeJaa8bWJ:1␤␤»

I think $x.re (Real part of $x) and $x.im (Imaginary part of $x)
should be allowed to be l-values.
What do you say? Will this affect the performance of Rakudo, Niecza ?

Recently substr-rw was split off from substr, so that now substr-rw is
the lvalue form. So maybe we can have $x.re-rw and $x.im-rw, but that
would be really ugly :)

-sisar

Moritz Lenz

unread,
May 19, 2012, 1:45:32 AM5/19/12
to perl6-l...@perl.org


On 05/19/2012 06:05 AM, Siddhant Saraf wrote:
> <sisar> r: my $x = 4 + 2i; $x.re = 5;
> <p6eval> rakudo 45679a: OUTPUT«Cannot assign to a non-container␤ in
> block <anon> at /tmp/PeeJaa8bWJ:1␤␤»
>
> I think $x.re (Real part of $x) and $x.im (Imaginary part of $x)
> should be allowed to be l-values.
> What do you say?

No.

Complex objects are value types and immutable.

It's bad enough that we conflate the container/value distinction for
substr-rw already, but we do it because it's quite useful.

But for complex numbers, it's not so useful, because you can just create
a new one quite easily:

$x = 5 + $x.im*i;

Cheers,
Moritz
0 new messages