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
The semantics of >>.foo feel wrong and possibly need changing #345
Comments
On more thoroughly grokking https://docs.raku.org/language/operators#methodop_»._/_methodop_%3E%3E this commit changes the functionality to be in concordance to the documentation and related tests on Hashes. See also Raku/problem-solving#345
Related: rakudo/rakudo@d0ec99a861 |
OK, I understand that it's about the difference between post and pre-decrement. $ raku -e 'say [1,2,3,4,5]»--'
[1 2 3 4 5] while raku -e 'say --«[1,2,3,4,5]'
[0 1 2 3 4] Yet doing the same on a BagHash still returns strange results using the stock Rakudo v2022.07: $ raku -e 'say --«<a b c d c d>.BagHash'
BagHash(d)
$ raku -e 'say --«<a b c d c d>.BagHash'
BagHash(c)
$ raku -e 'say --«<a b c d c d>.BagHash'
BagHash(c d) (Those are really three successive tests on my computer :-o ) |
That is what commit rakudo/rakudo@d0ec99a861 fixed: rakudo HEAD now says:
as expected. |
Quoting from https://docs.raku.org/language/operators#index-entry-hyper_%3C%3C-hyper_%3E%3E-hyper_%C2%AB-hyper_%C2%BB-Hyper_operators:
I think it makes sense that >>. behaves similarly, operating on the values of the Associative data types. I'm not sure if the issue was concerned with this approach but maybe it's good to point out that this seems to derived from related documented behavior. There are still problems with the semantics/documentation of hyper operators, I wanted to open an issue for that, getting into it now. EDIT: #346 is ready now. |
Aiui that doc is about binary op hypers ("both hashes", i.e. "missing keys" is about one hash having a key and the other not and so the direction controls whether the mismatch means that element is dropped or not), not unary ops like this issue. I'm not seeing a connection. |
I am making the connection by saying:
Since it seemed the "operating on the values" part may not be written down for the >>. call. |
This has been instigated by rakudo/rakudo#5057 .
I've come to the conclusion that my fix for that issue is either the wrong fix, or we need to rethink the semantics of >>.foo. The documentation currently states:
Now, clearly, that doesn't work for
Associative
s, as the "elements" ofAssociative
s arePair
s:So
Associative
s are handled differently by calling the operator on the values of theAssociative
.Now let's get back to the original example:
This now returns what the op expected. But that expectation was actually wrong, because if we do something similar with an array that is created on the fly:
will return a List of the return values in order And since
&postfix:<-->
returns the original value, the return value is actually a copy of the original array, and the decrements that have been done, are lost in the ether. If we want to be consistent with that behaviour, then:And those decrements would be lost in the ether as well. And would be contrary to expectations of the op as well.
The text was updated successfully, but these errors were encountered: