Skip to content

Commit

Permalink
Adds Boolean contexts refs #1225
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jul 30, 2019
1 parent 531e030 commit 3fb402a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions doc/Language/contexts.pod6
Expand Up @@ -168,6 +168,31 @@ C<but> creates a mixin, which endows the complex number with a C<Str> method.
C<put> contextualizes it into a string, that is, it calls C<Str>, the string
contextualizer, with the result shown above.
=head1 Boolean X<|Boolean context>
This context will force a variable to be interpreted as C<True> or C<False>.
say "Hey" if 7; # OUTPUT: «Hey␤»
say "Ahoi" if "";
This context appears in expressions such as C<if> or C<while>, and is
equivalent to calling C<so> on these values.
=for code
say "Hey" if 7.so; # OUTPUT: «Hey␤»
say "Ahoi" if not set().so; # OUTPUT: «Ahoi␤»
In general, non-zero, non-empty will be converted to C<True>; zero or empty
will be equivalent to False. But C<.so> can be defined to return any Boolean
value we want, so this is just a rule ov thumb.
C<?> and C<!> are the Boolean context operator and its negation. They will
force this context on an object.
=for code
say ? 0i; # OUTPUT: «False␤»
say ! :true; # OUTPUT: «False␤»
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit 3fb402a

Please sign in to comment.