is rw basically a null-op on objects/references?

0 views
Skip to first unread message

Ingo Blechschmidt

unread,
Apr 28, 2005, 8:30:34 AM4/28/05
to perl6-l...@perl.org
Hi,

does the following work as expected?

for %hash.pairs -> $pair { # Note: No "is rw"!
$pair.value = ...; # Modifies %hash
}

Or is it necessary to declare $pair as is rw? (The snippet does not
modify $pair, but $pair.value.)


--Ingo

--
Linux, the choice of a GNU | The next statement is not true.
generation on a dual AMD | The previous statement is true.
Athlon! |

Juerd

unread,
Apr 28, 2005, 8:47:46 AM4/28/05
to Ingo Blechschmidt, perl6-l...@perl.org
Ingo Blechschmidt skribis 2005-04-28 14:30 (+0200):

> does the following work as expected?
> for %hash.pairs -> $pair { # Note: No "is rw"!
> $pair.value = ...; # Modifies %hash
> }

Yes, because a pair is an object (reference), and it's not the .value
that you're passing ro.

I still want <->, by the way.


Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html

Juerd

unread,
Apr 28, 2005, 8:59:40 AM4/28/05
to Juerd, Ingo Blechschmidt, perl6-l...@perl.org
Juerd skribis 2005-04-28 14:47 (+0200):

> Yes, because a pair is an object (reference), and it's not the .value
> that you're passing ro.

An example of what would go wrong:

for %hash.pairs>>.value -> $value {
$value = ...;
}

But this will work:

for %hash.pairs>>.value {
$_ = ...;
}

And this again won't:

for %hash.pairs>>.value -> $_ {
$_ = ...;
}

This makes "upgrading" a block to use an explicit name a painful
experience if you happen to mutate its value, because you have to
specify 'is rw', which I'm sure will bite many people many times.

This is why I want <->, so that the default for

for ... { ... }

can be

for ... <-> $_ { ... }

rather than the unexpected

for ... -> $_ is rw { ... }

so that $_ is the default, and no special default-magic for "is rw" is
needed. Of course, "<-> $_" and "-> $_" are 100% equal internally.

Thomas Sandlaß

unread,
Apr 28, 2005, 12:09:34 PM4/28/05
to perl6-l...@perl.org
Juerd wrote:
> Ingo Blechschmidt skribis 2005-04-28 14:30 (+0200):
>
>>does the following work as expected?
>> for %hash.pairs -> $pair { # Note: No "is rw"!
>> $pair.value = ...; # Modifies %hash
>> }
>
>
> Yes, because a pair is an object (reference), and it's not the .value
> that you're passing ro.

I come to the some answer but with a different argument.
Calling the .value method on $pair is not considered a
write operation. And indeed the %hash could arrange for
staying unchanged by having a corresponding copy out
implementation of its .pairs method.


> I still want <->, by the way.

Me too. And I guess <- naturally completes the set.
Which in turn make me want the parameter traits
'is input' and 'is output'. The former is a synonym
(or replacement?) for 'is const'. Both together form
'is rw' which would be an abbreviation of 'is input&output'.


Regards,
--
TSa (Thomas Sandlaß)


Juerd

unread,
Apr 28, 2005, 1:29:58 PM4/28/05
to Thomas Sandlaß, perl6-l...@perl.org
Thomas Sandlaß skribis 2005-04-28 18:09 (+0200):

> >I still want <->, by the way.
> Me too. And I guess <- naturally completes the set.

Although it would complete the set, in the months since I first started
wanting <->, I have not been able to come up with a good reason to want
write-only binding.

A special case of <> parsing for <-> is not a big thing, but adding a
special case for <- would be, because the difference between /^-$/ and
/^-.*/ is potentially extremely huge.

(Note that only to the human eye it is a special case, and can look like
<>, if the parser is smart enough to simply try <-> as a whole before
trying to match <>. I wouldn't suggest actually parsing <.*> first and
then seeing if the .* happened to equal '-' :))

Reply all
Reply to author
Forward
0 new messages