Talk:Order disjoint list items: Difference between revisions

→‎Perl 6 entry: bags are smart enough to know when all the marbles of a given color are gone
(→‎Perl 6 entry: bags are smart enough to know when all the marbles of a given color are gone)
Line 11:
 
:: I agree with you, and I somehow missed the "N items chosen from M" part completely. I don't much care about the second test case, it's the first one that's important, but then I wrote it wrong: it's M = <X X Y> and N = <X>. Basically your test should read <tt>bag{$_}-- > 0</tt> instead of just a non-zero test, if Perl 6 hash works similarly to 5. --[[User:Ledrug|Ledrug]] ([[User talk:Ledrug|talk]]) 05:04, 13 May 2014 (UTC)
 
::: It still works as expected; we don't need to test for > 0 because bags are smart about going lower than 0, since you can't have a negative number of marbles in your bag. (The advantages of having a type system built in...) In fact, the hashes behind sets and bags automatically delete entries that go to False or 0. So the key lookup just returns an undefined value rather than 0, and the attempt to decrement that is likewise undefined, hence false in the boolean context. (Was throwing a bogus exception earlier, which we fixed earlier today, and that's why it requires a newer version. The first version I checked in would probably have run with an older rakudo, since it did the membership test separately from the decrement to get around the bug. Well, maybe it wouldn't, since we renamed BagHash a couple of months ago too.) Anyway, if sets and bags were just hashes in disguise with no additional behaviors, we probably wouldn't have bothered adding them. --[[User:TimToady|TimToady]] ([[User talk:TimToady|talk]]) 05:28, 13 May 2014 (UTC)
Anonymous user