diff --git a/doc/Language/contexts.pod6 b/doc/Language/contexts.pod6 new file mode 100644 index 000000000..cfbbacd5f --- /dev/null +++ b/doc/Language/contexts.pod6 @@ -0,0 +1,24 @@ +=begin pod :tag + +=TITLE Contexts and contextualizers + +=SUBTITLE What are contexts and how to get into them. + +A context is needed, in many occasions, to interpret the value of a container. In Perl 6, we will use context to coerce the value of a container into some type or class, or decide what to do with it, as in the case of tne sink context. + +=head1 Sink + +I is equivalent to C context, that is, a context in which we throw (down the sink, as it were) the result of an operation or the return value from a block. In general, this context will be invoked in warnings and errors when a statement does not know what to do with that value. + +=begin code +my $sub = -> $a { return $a² }; +$sub; # OUTPUT: «WARNINGS:␤Useless use of $sub in sink context (line 1)␤» +=end code + +You can force that sink context on Ls, by using the L|/routine/sink-all> method. Ls can also be L 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 are explicitly evaluated in sink context, with values returned explicitly using C. + +=end pod + +# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6