Perl6's ^^
Perl6's ^^
Posted Feb 17, 2015 20:22 UTC (Tue) by dlang (guest, #313)In reply to: Perl6's ^^ by mbunkus
Parent article: Scalar typing in the PHP world
Posted Feb 17, 2015 20:24 UTC (Tue)
by marcH (subscriber, #57642)
[Link]
By inventing a brand new type of short-circuit without bothering giving it a new name.
Who cares about confusion - it's only Perl after all.
Posted Feb 17, 2015 20:32 UTC (Tue)
by mbunkus (subscriber, #87248)
[Link] (12 responses)
It's been explained at least twice in this thread with links to Perl's man page giving examples for it.
Posted Feb 17, 2015 21:04 UTC (Tue)
by mathstuf (subscriber, #69389)
[Link] (11 responses)
That doesn't match the diagrams on Wikipedia on xor[1]. "true xor true xor true" is "false xor true" is "true". I don't see any reasonable reduction of it such that it can be false.
Posted Feb 17, 2015 21:11 UTC (Tue)
by mbunkus (subscriber, #87248)
[Link] (10 responses)
Posted Feb 17, 2015 22:20 UTC (Tue)
by mathstuf (subscriber, #69389)
[Link] (1 responses)
Posted Feb 17, 2015 23:15 UTC (Tue)
by mbunkus (subscriber, #87248)
[Link]
For me (and I'm really only speaking about myself here) having ^^ short-circuit is completely logical as all the other logical operators are short-circuiting as well. I find it easy to remember. Other people's brains work quite differently from my own, though, so of course they may find it a lot less logical or highly confusing.
For me »serious confusion« means a completely different set of topics in Perl. Those are also the things I dislike most about the language. For example: functions returning different results depending on context (wantarray – or the whole notion of having different contexts in the first place); the subtle but incredibly dangerous distinction between lists and arrays; all the magic and cryptically-named special variables ($_ or _ or $[ or $< or $/ or…).
Posted Feb 18, 2015 19:41 UTC (Wed)
by bronson (subscriber, #4806)
[Link] (7 responses)
The linked page says it, "returns the first true argument if there is only one, and Nil otherwise". How is that useful? Is it common enough to be worth making it an operator? I'd google but that would obviously be futile. :)
Posted Feb 18, 2015 19:56 UTC (Wed)
by marcH (subscriber, #57642)
[Link] (6 responses)
Having the logic of this new ^^ operator somewhat related to XOR... yet different makes the re-use of the ^ symbol even worse: even more confusing, even more error-prone.
The unusual short-circuit logic which triggers only with 3 operands or more and the confusing effect of parentheses are the icing on the cake of surprises.
This looks like a futile exercise in code obfuscation; let's just stop beating a dead horse.
Posted Feb 18, 2015 20:05 UTC (Wed)
by niner (subscriber, #26151)
[Link] (5 responses)
From Wikipedia:
List Operators
List operators construct a junction as a list:
my $options = any(1, 2, 3, 4); # Any of these is good
Infix Operators
Another way to specify a junction is to use infix operators like we have already seen:
my $options = 1 | 2 | 3 | 4; # Any of these is good
Posted Feb 18, 2015 20:19 UTC (Wed)
by marcH (subscriber, #57642)
[Link] (2 responses)
One of the most dramatic things Open-Source changed is the fact that code is read, reviewed, reworked and read again by many more random people from many more random places with many more random backgrounds and many more education and knowledge levels. From this specific perspective Perl (and I guess PHP too - dunno it enough) are missing the open source revolution, because of this completely off the mark "There is more than one way to do it" mantra.
No Larry, computer languages should not try to emulate the fuzziness of natural languages, absolutely not. Machines are machines and humans are humans; two very different things which complement each other and don't need to copy each other.
Posted Feb 19, 2015 7:31 UTC (Thu)
by niner (subscriber, #26151)
[Link] (1 responses)
Posted Feb 19, 2015 15:25 UTC (Thu)
by marcH (subscriber, #57642)
[Link]
Natural languages have redundancy, semantic overlap, fuzziness, assumptions,... These have pros and cons; one (limited) purpose: expressing nuances. In pure technical communications nuances are completely unnecessary; even harmful in programming languages and any specification. For instance a natural language like English is so poorly suited to protocol specification that readers typically complain that they feel like they are reading a new, foreign language.
For driving machines (including machines that could kill), a language model to follow is not natural languages but maths: high-level, expressive, very limited redundancy and most importantly of all: unambiguous. Who wants machines to do something... "maybe"? Merely changing the vocabulary is fine since this does not change the properties, however adding assumptions and/or redundancy only brings confusion with users constantly wondering about what they are reading.
[BTW you don't seriously think that a redundant and inconsistent ^^ operator brings Perl closer to natural languages, do you?]
Posted Feb 18, 2015 21:33 UTC (Wed)
by bronson (subscriber, #4806)
[Link] (1 responses)
I liked Perl5, and still have some modules on CPAN, but this sort of discussion is giving me the heebie jeebies... Perl6 seems to have a number of false friends (^ and xor) and subtle nuances to learn.
Posted Feb 19, 2015 7:27 UTC (Thu)
by niner (subscriber, #26151)
[Link]
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Junction operators are: none, one (^), any (|), all (&). The infix operators behave accordingly. As such ^^'s behavior is indeed consistent with the other operators.
my $requirements = all(5, 6, 7, 8); # All or nothing
my $forbidden = none(9, 10, 11); # None of these
my $onlyone = one(12, 13, 4); # One and only one
my $requirements = 5 & 6 & 7 & 8; # All or nothing
my $onlyone = 12 ^ 13 ^ 4; # One and only one
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
Perl6's ^^
^^ returns the first true argument if there is only one, and Nil otherwise.