Skip to content

Commit

Permalink
Some reflow and fixes format errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jul 9, 2018
1 parent 493b1e3 commit 63430f9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions doc/Language/contexts.pod6
Expand Up @@ -20,12 +20,16 @@ my $sub = -> $a { return $a² };
$sub; # OUTPUT: «WARNINGS:␤Useless use of $sub in sink context (line 1)␤»
=end code
X<|sinking>
You can force that sink context on L<Iterator>s, by using the L<C<sink-all>|/routine/sink-all> method. L<Proc>s can also be L<sunk via the C<sink> method|https://docs.perl6.org/type/Proc#method_sink>, forcing them to raise an exception and not returning anything.
X<|sinking> You can force that sink context on L<Iterator>s, by using the
L<C<sink-all>|/routine/sink-all> method. L<Proc>s can also be
L<sunk via the C<sink> method|https://docs.perl6.org/type/Proc#method_sink>,
forcing them to raise an exception and not returning anything.
In general, blocks will warn if evaluated in sink context; however, L<gather/take blocks|/language/control#Flow%29_gather_take> are explicitly evaluated in sink context, with values returned explicitly using C<take>.
In general, blocks will warn if evaluated in sink context; however,
L<gather/take blocks|/language/control#Flow%29_gather_take> are explicitly
evaluated in sink context, with values returned explicitly using C<take>.
In sink context, an object will call its `sink` method if present:
In sink context, an object will call its C<sink> method if present:
=begin code
sub foo {
Expand All @@ -42,17 +46,22 @@ foo
This context, and probably all of them except sink above, are I<conversion> or I<interpretation> contexts in the sense that they take an untyped or typed variable and duck-type it to whatever is needed to perform the operation. In some cases that will imply a conversion (from L<Str> to L<Int>, for instance); in other cases simply an interpretation (L<IntStr> will be interpreted as L<Int> or as L<Str>).
I<Number context> is called whenever we need to apply a numerical operation on a variable.
I<Number context> is called whenever we need to apply a numerical operation on a
variable.
=begin code
my $not-a-string="1 ";
my $neither-a-string="3 ";
say $not-a-string+$neither-a-string; # OUTPUT: «4␤»
=end code
In the code above, strings will be interpreted in numeric context as long as there is only some numbers and no other characters. It can have any number of leading or trailing whitespace, however.
In the code above, strings will be interpreted in numeric context as long as
there is only some numbers and no other characters. It can have any number of
leading or trailing whitespace, however.
Numeric context can be forced by using arithmetic operators such as C<+> or C<->. In that context, the L<C<Numeric>|/routine/Numeric> method will be called if available and the value returned used as the numeric value of the object.
Numeric context can be forced by using arithmetic operators such as C<+> or
C<->. In that context, the L<C<Numeric>|/routine/Numeric> method will be called
if available and the value returned used as the numeric value of the object.
=begin code
my $t = True;
Expand All @@ -64,7 +73,9 @@ my $list= <a b c>;
say True+$list; # OUTPUT: «4␤»
=end code
In the case of I<listy> things, the numeric value will be in general equivalent to C<.elems>; in some cases, like L<Thread|/Numeric#(Thread)_method_Numeric> it will return an unique thread identifier.
In the case of I<listy> things, the numeric value will be in general equivalent
to C<.elems>; in some cases, like L<Thread|/Numeric#(Thread)_method_Numeric> it
will return an unique thread identifier.
=head1 String X<|string context>
Expand Down

0 comments on commit 63430f9

Please sign in to comment.