Skip to content

Commit ce6422a

Browse files
committed
Adds string context
Refs #114 and #1225. There are still many contexts to go, but these are the three most important. I'll also revise #1225 to close it when enough meaningful contexts done. In general, most of them will be like * context Turns the object into * if possible, throws warning. So there's not much to them...
1 parent 08e976b commit ce6422a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

doc/Language/contexts.pod6

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
=SUBTITLE What are contexts and how to get into them.
66
7-
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.
7+
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 the sink context.
88
99
=head1 Sink
1010
@@ -47,6 +47,18 @@ say True+$list; # OUTPUT: «4␤»
4747
4848
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.
4949
50+
=head1 String
51+
52+
In a I<string context>, values can be manipulated as strings. This context is used, for instance, for printing values to standard output.
53+
54+
say $very-complicated-and-hairy-object; # OUTPUT: something meaningful
55+
56+
Or when smart-matching to a regular expression:
57+
58+
p6: say 333444777 ~~ /(3+)/; # OUTPUT: «「333」␤ 0 => 「333」␤»
59+
60+
In general, the L<C<Str> routine|/routine/Str> will be called on a variable to contextualize it; since this method is inherited from L<Mu>, it is always present, but it is not always guaranteed to work. In some core classes it will issue a warning.
61+
5062
=end pod
5163

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

xt/words.pws

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,3 +1369,5 @@ rhs
13691369
lhs
13701370
RHS
13711371
LHS
1372+
contextualizers
1373+
Procs

0 commit comments

Comments
 (0)