6
6
7
7
A context is needed, in many occasions, to interpret the value of a container.
8
8
In Perl 6, we will use context to coerce the value of a container into some type
9
- or class, or decide what to do with it, as in the case of the sink context.
9
+ or class, or in general decide what to do with it, as in the case of the sink
10
+ context.
10
11
11
12
= head1 Sink X < |sink context >
12
13
13
- I < Sink > is equivalent to C < void > context, that is, a context in which we throw
14
- (down the sink, as it were) the result of an operation or the return value from
15
- a block. In general, this context will be invoked in warnings and errors when a
16
- statement does not know what to do with that value.
14
+ The I < sink > context is equivalent to what in other languages is called C < void >
15
+ context, that is, a context in which we throw (down the sink, as it were) the
16
+ result of an operation or the return value from a block. In general, this
17
+ context will be invoked in warnings and errors when a statement does not know
18
+ what to do with that value.
17
19
18
20
= begin code
19
21
my $sub = -> $a { return $a² };
20
22
$sub; # OUTPUT: «WARNINGS:Useless use of $sub in sink context (line 1)»
21
23
= end code
22
24
23
- X < |sinking > You can force that sink context on L < Iterator|/type/Iterator > s, by
25
+ X < |sinking >
26
+ You can force that sink context on L < Iterator|/type/Iterator > s, by
24
27
using the L < C < sink-all > |/routine/sink-all> method. L < Proc|/type/Proc > s can also
25
28
be L < sunk via the C < sink > method|/type/Proc#method_sink > , forcing them to raise
26
29
an exception and not returning anything.
@@ -39,17 +42,16 @@ sub foo {
39
42
method sink { say "sink called" }
40
43
}
41
44
}
42
- foo
43
- # OUTPUT: sink called
45
+ foo; # OUTPUT: sink called
44
46
= end code
45
47
46
48
47
49
= head1 Number X < |number context >
48
50
49
- This context, and probably all of them except sink above, are I < conversion > or
50
- I < interpretation > contexts in the sense that they take an untyped or typed
51
- variable and duck-type it to whatever is needed to perform the operation. In
52
- some cases that will imply a conversion (from L < Str|/type/Str > to
51
+ This context, and probably all other contexts except I < sink > above, are
52
+ I < conversion > or I < interpretation > contexts in the sense that they take an
53
+ untyped or typed variable and duck-type it to whatever is needed to perform the
54
+ operation. In some cases that will imply a conversion (from L < Str|/type/Str > to
53
55
L < Numeric|/type/Numeric > , for instance); in other cases simply an interpretation
54
56
(L < IntStr|/type/IntStr > will be interpreted as L < Int|/type/Int > or as
55
57
L < Str|/type/Str > ).
@@ -82,7 +84,8 @@ say True+$list; # OUTPUT: «4»
82
84
= end code
83
85
84
86
In the case of I < listy > things, the numeric value will be in general equivalent
85
- to C < .elems > ; in some cases, like L < Thread|/routine/Numeric#(Thread)_method_Numeric > it
87
+ to C < .elems > ; in some cases, like
88
+ L < Thread|/routine/Numeric#(Thread)_method_Numeric > it
86
89
will return an unique thread identifier.
87
90
88
91
= head1 String X < |string context >
0 commit comments