New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior of »-- #5057
Comments
Good catch! This is indeed weird. But the
|
Yes, your version works fine here too! |
also does the right thing. |
Some progress: It turns out that in the case of the error, it is always the first key that is being decremented, that loses its decrement. If that is one of the higher valued keys, then you won't notice it unless you actually look at the value. If it is one the keys that has a value of |
FWIW, this is the golf I'm working on ATM:
as the |
Another datapoint: |
|
Another Datapoint:
Note that the increments somehow got lost :-( |
Spotted in #5057 . The above basically runs QuantHash.new(1,2,3,4,1,2).deepmap(&postfix:<-->) The problem was caused by there being an Associative candidate for deepmap, and QuantHashes being Associative. Since .deepmap is supposed to *return* an object of the *same* type, this effectively means a new object needs to be created. In the case of the code in the issue, essentially: $ raku -e 'my $a=‘abcdeabc’.comb.BagHash»--; $a.keys.sort.say' there would be a BagHash object created, but then the deepmap logic for Associatives would do some magic that would do the wrong thing for QuantHashes (and possibly for Hash and Map as well, but that requires further investigation). The result was that the order in which updates where being done, got confused, and the new BagHash object got mutilated. This commit adds specific Setty, Baggy and Mixy candidates for deepmap, that actually uses information about the internal structure of the QuantHashes to allow a fast creation of the new, updated object. This allows >>-- to even work on immutable QuantHashes (as we create a new immutable object under the hood). So this now works: $ raku -e 'say ‘abcdeabc’.comb.Bag»--' Bag(a b c)
Ok, finally got to the bottom of this: 63d03eb899 |
d0ec99a861 changed the example:
and this is correct, as the increments happen on the original Adding parentheses to make sure that
So I'm now closing this issue, now that we hopefully have full clarity on the issue at hand, and its resolution. |
I was toying with the code shown in this blog post Assuming optionality and I realized that running the following one-liner repeatedly:
$ raku -e'my BagHash $a=‘Perl Weekly Challenge’.comb.BagHash»--;$a.keys.sort.say'
got me different results, such as:
OTOH, the following:
$ raku -e'my BagHash $a=‘Perl Weekly Challenge’.comb.BagHash;$a.keys.sort.say'
always returns the same result, so I guess that the problem lays with the '»--'.
I'm running Rakudo v2022.07 on Debian sid.
The text was updated successfully, but these errors were encountered: