Skip to content

Commit 91eb48a

Browse files
authored
Unified format of code block
and delete redundant links
1 parent 46e6c13 commit 91eb48a

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

doc/Language/objects.pod6

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,33 @@ object. That includes literals, types (type objects), code and containers.
2222
2323
To call a method on an object, add a dot, followed by the method name:
2424
25-
=for code :allow<B L>
26-
L<say> "abc"B<.L<uc>>;
25+
=for code
26+
say "abc".uc;
2727
# OUTPUT: «ABC␤»
2828
29-
This calls the L<C<uc>|uc> method on C<"abc">, which is an object of type
30-
L<C<Str>|Str>. To supply arguments to the method, add arguments inside parentheses
29+
This calls the C<uc> method on C<"abc">, which is an object of type
30+
C<Str>. To supply arguments to the method, add arguments inside parentheses
3131
after the method.
3232
33-
=for code :allow<B L>
34-
my $formatted-text = "Fourscore and seven years ago...".L<indent>B<(8)>;
33+
=for code
34+
my $formatted-text = "Fourscore and seven years ago...".indent(8);
35+
say $formatted-text;
36+
# OUTPUT: « Fourscore and seven years ago...␤»
3537
3638
C<$formatted-text> now contains the above text, but indented 8 spaces.
3739
3840
Multiple arguments are separated by commas:
3941
40-
=for code :allow<B L> :preamble<my $formatted-text;>
42+
=for code :preamble<my $formatted-text;>
4143
my @words = "Abe", "Lincoln";
42-
@words.L<push>("said"B<,> $formatted-text.L<comb>(L</\w+/|/language/regexes>));
44+
@words.push("said", $formatted-text.comb(/\w+/));
45+
say @words;
46+
# OUTPUT: «[Abe Lincoln said (Fourscore and seven years ago)]␤»
4347
4448
Multiple arguments can be specified by separating the argument list with a colon:
4549
46-
=for code :allow<B L> :preamble<my @words;>
47-
say @words.L<join>: '--';
50+
=for code :preamble<my @words;>
51+
say @words.join: '--';
4852
# OUTPUT: «Abe--Lincoln--said--Fourscore--and--seven--years--ago␤»
4953
5054
Since you have to put a C<:> after the method if you want to pass arguments
@@ -63,12 +67,11 @@ Methods can return mutable containers, in which case you can assign to the
6367
return value of a method call. This is how read-writable attributes to
6468
objects are used:
6569
66-
=for code :allow<L>
67-
$*IN.L<nl-in> = "\r\n";
70+
=for code
71+
$*IN.nl-in = "\r\n";
6872
6973
Here, we call method C<nl-in> on the C<$*IN> object, without arguments,
70-
and assign to the container it returned with the
71-
L<C<=>|=> operator.
74+
and assign to the container it returned with the L<C<=>|=> operator.
7275
7376
All objects support methods from class L<Mu>, which is the type hierarchy root.
7477
All objects derive from C<Mu>.
@@ -77,46 +80,42 @@ All objects derive from C<Mu>.
7780
7881
Types themselves are objects and you can get the I<type object> by writing its name:
7982
80-
my $int-type-obj = Int;
83+
=for code
84+
my $int-type-obj = Int;
8185
8286
You can ask any object for its type object by calling the C<WHAT> method
8387
(which is actually a macro in method form):
8488
8589
=for code :ok-test<WHAT>
86-
my $int-type-obj = 1.WHAT;
90+
my $int-type-obj = 1.WHAT;
8791
8892
Type objects (other than L<Mu>) can be compared for equality with the
8993
L<C<===>|===> identity operator:
9094
91-
=begin code :allow<B L> :ok-test<WHAT>
92-
95+
=for code :ok-test<WHAT>
9396
sub f(Int $x) {
94-
if $x.WHAT B<L<===>> Int {
97+
if $x.WHAT === Int {
9598
say 'you passed an Int';
9699
}
97100
else {
98101
say 'you passed a subtype of Int';
99102
}
100103
}
101-
=end code
102104
103105
Although, in most cases, the L<C<.isa>|isa> method will suffice:
104106
105-
=begin code :allow<B L>
106-
107+
=for code
107108
sub f($x) {
108-
if $xB<.L<isa>>(Int) {
109+
if $x.isa(Int) {
109110
...
110111
}
111112
...
112113
}
113114
114-
=end code
115-
116-
Subtype checking is done by smart-matching:
115+
Subtype checking is done by X<smart-matching|smartmatch operator>:
117116
118-
=for code :allow<B L> :preamble<my $type;>
119-
if $type B<L<~~>> L<Real> {
117+
=for code :preamble<my $type;>
118+
if $type ~~ Real {
120119
say '$type contains Real or a subtype thereof';
121120
}
122121

0 commit comments

Comments
 (0)