You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class MagicVal {
has Int $.constant;
has Int $.varies = 0;
method varies is rw {
$count++;
return-rw Proxy.new(
# note that FETCH and STORE cannot go through the accessors
# of $.varies again, because that would lead to infinite
# recursion. Use the actual attribute here instead
FETCH => method () { $!varies },
STORE => method ($new) { $!varies = $new + 1 },
);
}
}
my $mv = MagicVal.new(:constant(6), :varies(6));
say $mv.varies.VAR.^name; # Proxy
say $mv.varies.^name; # Method
<moritz> m: https://gist.github.com/moritz/5cda6371ab3cfec3254e
<camelia> rakudo-moar 0132b6: OUTPUT«ProxyMethod»
<moritz> why does the last line print Method here?
<moritz> and not Int?
<masak> good question.
<masak> does just `$mv.varies` print 6?
<moritz> masak: no, it says <anon>
<masak> sounds wrong to me.
<ShimmerFairy> moritz: Well, it's because you mapped those keys to
Method objects, no?
<masak> ShimmerFairy: isn't that the way you implement a Proxy, though?
<masak> you give FETCH and STORE a callable each. doesn't mean they get exposed.
<ShimmerFairy> masak: I've never seen the method keyword used with it,
I don't think. Just plain closures
<masak> ShimmerFairy: the presence of the `method` keyword there is
practically irrelevant.
<moritz> ShimmerFairy: the 'method' keyword just means they get an invocant
<masak> m: my &c1 = sub ($obj, $x) { say "$obj: $x" }; my &c2 = method
($obj: $x) { say "$obj: $x" }; c1("OH HAI", 42); "OH HAI".&c2(42)
<camelia> rakudo-moar 0132b6: OUTPUT«OH HAI: 42OH HAI: 42»
<masak> ShimmerFairy: ^
<masak> it's only a matter of intent, not a matter of differing semantics.
<moritz> huh
<moritz> but changing it to a sub instead helps indeed
<moritz> wtf?
<masak> ok, bug
* masak submits rakudobug
<masak> it's probably special-cased where it oughtn't be
<jdv79> i think i ran into that a few months ago and just ignored it
when someone showed me the working one
<masak> let's fix it instead :P
Migrated from rt.perl.org#126198 (status was 'new')
Searchable as RT126198$
The text was updated successfully, but these errors were encountered: