Permalink
Browse files

explain autothreading and negated operators

  • Loading branch information...
1 parent 792ea01 commit de7f6db001055415687d17f096bacd9f56cf652c @moritz moritz committed Jul 31, 2012
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/Junction.pod
View
@@ -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>

0 comments on commit de7f6db

Please sign in to comment.