Last active
August 29, 2015 14:01
-
-
Save lizmat/7f7ecc7fdbd4152c9932 to your computer and use it in GitHub Desktop.
Can someone explain why FETCH is called *EIGHT* times ???
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A is Hash { | |
method at_key(A:D $hash: $k) { | |
Proxy.new( | |
FETCH => { | |
say "in FETCH with $k"; | |
$hash.exists_key($k) ?? $hash{$k} !! Int; | |
}, | |
STORE => -> $old, $new { | |
if $new > 0 { | |
$hash{$k} = $new; | |
$new; | |
} | |
elsif $new == 0 { | |
$hash.delete_key($k); | |
$new; | |
} | |
else { # we don't know about negative values | |
Int; | |
} | |
} | |
); | |
} | |
} | |
my $a = A.new; | |
say $a<b>++; | |
======================================== | |
in FETCH with b | |
in FETCH with b | |
in FETCH with b | |
in FETCH with b | |
in FETCH with b | |
in FETCH with b | |
in FETCH with b | |
in FETCH with b | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment