60 points · by kumaranvpl · 9y ago · 34 comments
It's so ugly, with so many arcane things to remember, with so many weird naming conventions that just don't make any sense to me.
> We intersected two sets with the ∩, U+2229 INTERSECTION, intersection operator and received a set that contains only the elements present in both original sets.
I'm not against having built-in Unicode operators, but the non-Unicode version should be the name of the character. What's the non-Unicode version of "∩"? Obviously it's "(&)"! Good thing there are only 57 of them to remember!
I tried to enter "∩" just now in Emacs: (ctrl-x, 8, enter, i, n, t, tab, r, tab, s, e, c, tab). It would have been shorter to just type "intersection"... And why is that called the "Texas" version?
That convention has decades of precedence in programming:
int bitset_a = 0x01234567, bitset_b = 0x89ABCDEF;
int bitset_c = bitset_a & bitset_b;
And at least a century in math.It also has an Emacs section. For a more detailed explanation for Emacs see my blog post: https://blog.ciavash.name/2016/01/09/entering-perl6-unicode-...
I find that pretty obvious, actually. After all
A ∩ B = { x ∈ A & x ∈ B }And it's still kind of confusing. If the goal is to match math notation then wouldn't (^) or (+) make more sense?
A ∩ B = { x ∈ A ∧ x ∈ B }Not necessarily. & is the ASCII symbol associated with logical 'and' that most programming languages have settled on, including Perl6, so for internal consistency, it makes sense to use it. Also note that the ampersand, while pretty rare, is sometimes used for that purpose in mahematical notation (https://en.wikipedia.org/wiki/List_of_logic_symbols).
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?Edit: these things are weird though. https://docs.perl6.org/type/IntStr
perl6 -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.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.
.put for @wanted.combinations.grep: { $materials ≽ [⊎] |$^stuff-we-want };
and the preceding lines for some time, and then read the description, clicked through a few of the links on the different operators and read the explanations of those, and then I finally understood what was happening here. I worry, though, that at this point in my life I would either 1) never be able to remember all this stuff; 2) even if I could remember it, never be in a position where it would dawn on me that whatever I was trying to do was a good fit for it.[1] Meaning I like having lots of features in my toolbox.
[2] And, amazingly, Rakudo is a pretty compact executable compared to most other langs.
> Set types always have True as values, and since we don’t care about iterating over Pair objects in our loop, we use the keys [function] to get just the keys of the set: the email addresses.
The impression I took away from that was that you needed to make sure to pass keys(@set) rather than just @set in the operator, or else you'd get weirdness in the result. Having just installed Rakudo and fired up a REPL to find out for myself what'd happen, I find:
- that my understanding from the post was erroneous
- that there's some kind of weird set/string coercion going on that isn't replicable in the terms the REPL uses to describe it
- that the given examples do not reliably generalize
- that nothing which seems to make sense actually works
- that nothing which seems to work actually makes sense
- that I'm now bleeding slightly from both caruncles.
Having not closely followed the Perl 6 development process, I am very glad to see it has taken on board the frequently uttered and extremely well justified criticism of Perl 5 that it's not consistent enough, and that there are so many syntactic and semantic special cases that no one who doesn't heavily specialize in the language can use it very reliably.
In Perl? Never!