3 ms·
say 42 ∈ <42 55 1>; # False; ∈ operator cares about object identity As an outsider, this seems like a huge gotcha. I suppose the weirdest thing (after read
by zokier 10y ago
say 42 ∈ <42 55 1>; # False; ∈ operator cares about object identity
As an outsider, this seems like a huge gotcha. I suppose the weirdest thing (after reading some docs) is why < > quotation is used as a set literal here. Would something like
say 42 ∈ (42, 55, 1);
work as expected? Or what would be the canonical way of writing an Int (not IntStr) set literal?
- labster 10y agoperl6 -e 'say 42 ∈ (42, 55, 1)' True That works fine -- and probably better than the quote-words operator <>. ∈ works on anything list-like, not just set types.
- sp332 10y agoThe angle brackets are explicitly string operators. So the set contains the string "42" but not the number 42. Perl does generally have different operators for strings vs numbers, so that's something you'd be used to thinking about already. Probably not a huge gotcha. Edit: these things are weird though. https://docs.perl6.org/type/IntStr https://docs.perl6.org/type/IntStr
- ab5tract 10y agoTo clarify, it isn't being used as a set literal. It's a list passed to an operator that happily coerces your lists to sets. Allomorphs are tricky things, but I think it was the right decision to treat them separately in collections. `Set.new(42, 55, 1)` is the most formal way to create a new set, but Perl 6 provides `set(42, 55, 1)` as a shorthand.