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
Improved behavior for symmetric difference #911
Conversation
|
Tests are available in this PR Raku/roast#179 |
|
Oh, also, I had taken the approach to carefully only coerce those elements which needed coercing, but somehow this broke the behavior of That is probably a separate bug in one of the other set operators referenced in |
|
I'm also spotting some quirky behaviour, which I'm unsure whether it's intentional or just missed edge-case handling:
|
Which I take to mean this PR is fine. @ab5tract would you be able to fix the negatives, though? From what I understand, under the new behaviour, |
|
The negatives seem to be an issue with ∪ and not to do with this PR. Merged. Thanks. |
Tests made passing by rakudo/rakudo#911 RT#124529: https://rt.perl.org/Public/Bug/Display.html?id=124529
|
Oops... That didn't go too well and I ended up reverting both this PR and roast changes. I totally missed that this changed test was not a fudged test. The particular issue is that test exists in 6.c-errata. As we make a promise to our users that a 6.c compiler will pass all of those tests, we cannot introduce changes that break those tests. You can consider proposing these changes in the v6.d document. But note the tests that broke refer to RT#1311476 where @pmichaud does say that the operator's current behaviour is the desired result. |
|
When I was hacking the branch, I was thinking against @pmichaud 's interpretation so that there would be a homogeneity of behavior between Phrased differently, I think the sensible behavior for n args to That then raises a question: We could potentially apply a similar logic to the Mix and Bag variants: only keys with matching weights in n-1 Sets will exist in the returning object. Mixes and Bags are then mainly incompatible except where a Mix contains integers as weights. Part of me prefers that, to be honest. Maybe the behavior in this PR could then be reproduced in a different "set" (really more of a mix/bag) operator? |
|
TimToady actually convinced me of the viewpoint that a Set is a degenerate Bag/Mix and I think what this PR did, to subtract lower weight from higher weight, is correct (and anyone who wants a Setty behaviour can just coerce their Bag/Mix to sets first). So the new behaviour would be as this PR implemented: that The only thing different from this PR that is needed is to maintain the behaviour for n-args, as far as what/how the args get excluded/subtracted, etc (no idea if that's even compatible or not). (P.S: I already fixed the issue with negative weights being ignored by ∪ operator). |
|
Okay, that should be fairly straightforward. Thanks for fixing ∪ , and the shout out! |
Previously the symmetric difference operator would only return a
Set. This is in contrast to some fudged tests and (likely) against expectations of DWIMiness by the user.This patch changes the behavior such that chained symmetric difference invocations will evaluate one pair at a time. This changes the expectations found in the
S03-operators/set.ttests, which appeared to be doing some form of conjoined evaluation.Instead, the results look like:
Step by step:
This also means that
MixandBagsymmetric difference operations can be sensibly chained:Symmetric difference is not actually symmetric when chained (order matters). This patch takes a "higher orders of complexity have priority" approach. You could also argue that it is
Setwhich should have precedence overMixorBag, such that:All the keys in
$sare present in the symmetric difference of$m (^) $b (^) $b, so the result is an empty set.In my opinion we lose a lot of the utility of
(^)if we take this set-centric approach, but I felt it worth mentioning in case someone has strong opinions in the other direction.