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! |
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
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.
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ß)
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 '-' :))