Skip to content

Commit

Permalink
explain autothreading and negated operators
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jul 31, 2012
1 parent 792ea01 commit de7f6db
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Junction.pod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ Usage examples:
my @primes_ending_in_1 = grep &is_prime & / 1$ /, 2..100;
say @primes_ending_in_1; # 11 31 41 61 71
Negated operators are special-cased when it comes to autothreading.
C<$a !op $b> is rewritten internally as C<!($a op $b)>. The outer
negation collapses any junctions, so the return value always a plain
L<Bool>.
my $word = 'yes';
my @negations = <no none never>;
if $word !eq any @negations {
say '"yes" is not a negation';
}
Note that without this special-casing, an expression like
C<$word ne any @words> would always evaluate to C<True> for non-trivial lists
on one side.
For this purpose, C<< infix:<ne> >> counts as a negation of C<< infix:<eq> >>.
In general it is more readable to use a positive comparison operator and
a negated junction:
my $word = 'yes';
my @negations = <no none never>;
if $word eq none @negations {
say '"yes" is not a negation';
}
=head1 See Also
=item L<http://perlgeek.de/blog-en/perl-5-to-6/08-junctions.html>
Expand Down

0 comments on commit de7f6db

Please sign in to comment.