Skip to content

Commit

Permalink
Align Mu.so & Mu.not docs with design
Browse files Browse the repository at this point in the history
The previous explanation of so() (double-negation) wasn't consistent
with implementation or mentioned in design docs. It's a common
JavaScript idiom but not relevant to Perl 6. This aligns with the docs
for prefix:<so> and :<not>, too. Ref Raku#2693.
  • Loading branch information
softmoth committed Mar 25, 2019
1 parent 86ab3c5 commit 7a7f642
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions doc/Type/Mu.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,10 @@ Returns the given item to the enclosing C<gather> block, without introducing a n
method so()
Returns a C<Bool> value representing the result of negating (with implicit
conversion to C<Bool>) the expression and then again computing the negation of
the result, thus computing the C<Bool> equivalent to the original expression.
Evaluates the item in boolean context (and thus collapses Junctions),
and returns the result.
It is the opposite of C<not>, and equivalent to the
L«C<?> operator|/language/operators#prefix_?».
One can use this method similarly to the English sentence: "If that is B<so>,
then do this thing". For instance,
Expand All @@ -622,27 +623,24 @@ then do this thing". For instance,
say "Verbose option detected in arguments";
} # OUTPUT: «Verbose option detected in arguments␤»
The C<$verbose-selected> variable in this case contains a
L<C<Junction>|/type/Junction>, whose value is C<any(any(False, False),
any(False, False), any(False, False), any(True, False))>. That is actually a
I<truish> value; thus, negating it will yield C<False>. The negation of that
result will be C<True>. C<so> is performing all those operations under the hood.
=head2 method not
method not()
Returns a C<Bool> value representing the logical negation of an expression.
Thus it is the opposite of C<so>.
Evaluates the item in boolean context (and thus collapses Junctions),
and negates the result.
It is the opposite of C<so>, and equivalent to the
L«C<!> operator|/language/operators#prefix_!».
my @args = <-a -e -b>;
my $verbose-selected = any(@args) eq '-v' | '-V';
if $verbose-selected.not {
say "Verbose option not present in arguments";
} # OUTPUT: «Verbose option not present in arguments␤»
Since there is also a prefix version of C<not>, the above code reads better
like so:
Since there is also a
L«prefix version of C<not>|/language/operators#prefix_not»,
this example reads better as:
my @args = <-a -e -b>;
my $verbose-selected = any(@args) eq '-v' | '-V';
Expand Down

0 comments on commit 7a7f642

Please sign in to comment.