Skip to content

Commit 4830298

Browse files
committed
Fixes errors
Basically changes say to put, which always calls Str (while say calls .gist). Closes #2546
1 parent 800a5b9 commit 4830298

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

doc/Language/contexts.pod6

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ foo
4444
4545
=head1 Number X<|number context>
4646
47-
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|/type/Str> to L<Numeric|/type/Numeric>, for instance); in other cases simply an interpretation (L<IntStr|/type/IntStr> will be interpreted as L<Int|/type/Int> or as L<Str|/type/Str>).
47+
This context, and probably all of them except sink above, are I<conversion> or
48+
I<interpretation> contexts in the sense that they take an untyped or typed
49+
variable and duck-type it to whatever is needed to perform the operation. In
50+
some cases that will imply a conversion (from L<Str|/type/Str> to
51+
L<Numeric|/type/Numeric>, for instance); in other cases simply an interpretation
52+
(L<IntStr|/type/IntStr> will be interpreted as L<Int|/type/Int> or as
53+
L<Str|/type/Str>).
4854
4955
I<Number context> is called whenever we need to apply a numerical operation on a
5056
variable.
@@ -56,7 +62,7 @@ say $not-a-string+$neither-a-string; # OUTPUT: «4␤»
5662
=end code
5763
5864
In the code above, strings will be interpreted in numeric context as long as
59-
there is only some numbers and no other characters. It can have any number of
65+
there are only a few digits and no other characters. It can have any number of
6066
leading or trailing whitespace, however.
6167
6268
Numeric context can be forced by using arithmetic operators such as C<+> or
@@ -84,16 +90,16 @@ used, for instance, for coercing non-string values so that they can be printed
8490
to standard output.
8591
8692
=for code :preamble<my $very-complicated-and-hairy-object>
87-
say $very-complicated-and-hairy-object; # OUTPUT: something meaningful
93+
put $very-complicated-and-hairy-object; # OUTPUT: something meaningful
8894
8995
Or when smartmatching to a regular expression:
9096
91-
say 333444777 ~~ /(3+)/; # OUTPUT: «「333」␤ 0 => 「333」␤»
97+
put 333444777 ~~ /(3+)/; # OUTPUT: «「333」␤ 0 => 「333」␤»
9298
9399
In general, the L<C<Str> routine|/routine/Str> will be called on a variable to
94-
contextualize it; since this method is inherited from L<Mu|/type/Mu>, it is always
95-
present, but it is not always guaranteed to work. In some core classes it will
96-
issue a warning.
100+
contextualize it; since this method is inherited from L<Mu|/type/Mu>, it is
101+
always present, but it is not always guaranteed to work. In some core classes it
102+
will issue a warning.
97103
98104
L<C<~>|/routine/~> is the (unary) string contextualizer. As an operator, it
99105
concatenates strings, but as a prefix operator it becomes the string context
@@ -116,7 +122,7 @@ string:
116122
say [~] [] ; # OUTPUT: «␤»
117123
118124
Since L<C<~> acts also as buffer concatenation operator|/routine/~#(Operators)_infix_~>,
119-
using it will
125+
it will
120126
have to check that every element is not empty, since a single empty buffer in
121127
string context will behave as a string, thus yielding an error.
122128
@@ -130,8 +136,7 @@ my $non-empty = Buf.new(0x3, 0x33);
130136
my $empty = [];
131137
my $non-empty-also = Buf.new(0x2,0x22);
132138
say [~] $non-empty, $empty, $non-empty-also;
133-
# OUTPUT: «(exit code 1) Cannot use a Buf as a string, but you called the Stringy method on it
134-
# in block <unit> at /tmp/bO_heb6AS9 line 1␤␤»
139+
# OUTPUT: «Cannot use a Buf as a string, but you called the Stringy method on it
135140
=end code
136141
137142
Since C<~> is putting in string context the second element of this list,
@@ -140,22 +145,23 @@ using the second form that applies to strings, thus yielding the shown error.
140145
Simply making sure that everything you concatenate is a buffer will avoid this
141146
problem.
142147
143-
my $non-empty = Buf.new(0x3, 0x33);
144-
my $empty = Buf.new();
145-
my $non-empty-also = Buf.new(0x2,0x22);
146-
say [~] $non-empty, $empty, $non-empty-also; # OUTPUT: «Buf:0x<03 33 02 22>␤»
148+
=for code
149+
my $non-empty = Buf.new(0x3, 0x33);
150+
my $empty = Buf.new();
151+
my $non-empty-also = Buf.new(0x2,0x22);
152+
say [~] $non-empty, $empty, $non-empty-also; # OUTPUT: «Buf:0x<03 33 02 22>␤»
147153
148154
In general, a context will coerce a variable to a particular type by calling the
149155
contextualizer; in the case of mixins, if the context class is mixed in, it will
150156
behave in that way.
151157
152158
my $described-number = 1i but 'Unity in complex plane';
153-
say $described-number; # OUTPUT: «Unity in complex plane␤»
159+
put $described-number; # OUTPUT: «Unity in complex plane␤»
154160
155161
C<but> creates a mixin, which endows the complex number with a C<Str> method.
156-
C<say> puts into string context, that is, it calls C<Str>, the string
162+
C<put> contextualizes it into a string, that is, it calls C<Str>, the string
157163
contextualizer, with the result shown above.
158164
159165
=end pod
160166

161-
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
167+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)