4 ms·
My God. Here's their example of the "reduction meta operator". say [+] 1...5; # sum say [*] 1...5; # product say [<] @list; # is @l
by shrughes 18y ago
My God. Here's their example of the "reduction meta operator".
say [+] 1...5; # sum
say [*] 1...5; # product
say [<] @list; # is @list strictly ordered ascendingly?
What the hell? With [*] they go for a reduction, but with [<] they go for a reduction over a zip of the list with its own tail. The behavior changes completely! How do you predict that? That's simply dumb. Extremely dumb. Things like this don't make the language complicated, they make it risky. It is risky to write Perl 6 programs. And we know programs don't get any thrill out of that.
- kingkongrevenge 18y agoOperators operate on the list. Conditions test the list. How is that confusing?
- shrughes 18y agoIt's completely different behavior depending on the type of operator. Edit: And apparently it even respects the associativity of the operator! There is nothing gained by making the language more complicated just to cut a few characters.
- kingkongrevenge 18y agoIsn't this like complaining that '[how the hell do you escape two asterisks?]' for exponentiation is too confusing?
- shrughes 18y agoYou're not reading what I've said, are you.
- utx00 18y agoyeah. i don't really get what is being gained. you have to keep some much context in your head in order to write perl - as compared to python ... it's tiring (as i keep saying)
- wolverian 18y agoIf you use the operator, it's (hopefully) safe to assume you know what it does. Then you should also know what interleaving the operator between the list elements does. Which is exactly what the reduction does. I don't understand your problem with it.
- scott_s 18y agoIt's all about context. The more of the enclosing context you need to keep in mind to understand a line of code, the more you increase the cognitive load on the programmer.
- halo 18y agoThe syntax seems perfectly reasonable, or even natural, to me. Perhaps you're over-thinking the specifics, or are too used to other functional programming languages where 'reduction' has a slightly different, more specific, meaning (i.e. fold). [+] 1...5 = 1+2+3+4+5 [*] 1...5 = 1*2*3*4*5 [**] 1...5 = 1**2**3**4**5 [<] 1...5 = 1<2<3<4<5 Note that this means, unlike the normal reduce, that it follows the operator's default precedence rules, and presumably the less-than operator works similarly to Python's in that it allows comparison chaining (i.e. 1 < 2 < 3 works as you'd expect) to make the result using reduce seem natural.
- deleted 18y ago[deleted]
- chromatic 18y agoYou predict what a hyperoperator does by knowing what the non-hyper operator does. Your question about predictability reads to me like asking "You can modify verbs with adverbs! How in the world do you know what a verb means?"