Skip to content

Commit 2f06e02

Browse files
authored
document named arrays, and add some second-level headings (#4677)
1 parent e648ccd commit 2f06e02

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

doc/Language/create-cli.rakudoc

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Hello, paul
113113
Hello, mary
114114
=end code
115115

116+
=head2 Multiple named parameters, and C<where> clauses
117+
116118
A more complicated example using a single positional and multiple
117119
named parameters, and also showing that C<where> clauses can also be applied
118120
to C<MAIN> arguments:
@@ -157,7 +159,11 @@ Usage:
157159
=end code
158160

159161
Although you don't have to do anything in your code to do this, it may still
160-
be regarded as a bit terse. But there's an easy way to make that usage
162+
be regarded as a bit terse.
163+
164+
=head2 Improve usage messages with rakudoc comments
165+
166+
But there's an easy way to make that usage
161167
message better by providing hints using pod features:
162168

163169
=for code :method<False>
@@ -210,6 +216,8 @@ Usage:
210216
-v Display verbose output
211217
=end code
212218

219+
=head2 Command lines and usage messages: more examples
220+
213221
The following are valid ways to call C<demo>:
214222

215223
=for code :lang<text>
@@ -253,6 +261,7 @@ And here's the signature that produces each type of argument:
253261
C<True> (because passing an option without an argument is equivalent
254262
to passing C<True>)
255263

264+
=head2 Aliases for named parameters
256265

257266
As any other subroutine, C<MAIN> can define
258267
L<aliases|/language/signatures#Argument_aliases> for its named parameters.
@@ -279,6 +288,34 @@ Usage:
279288
--verbose required verbosity
280289
=end code
281290

291+
=head2 Named arrays
292+
293+
The MAIN subroutine can also use a kind of named parameter not available
294+
to ordinary subs: the named array. This enables, for instance, providing
295+
two different short arrays as arguments on a command line.
296+
297+
Declare a named-array parameter with C<:@> in sub MAIN's signature:
298+
299+
# inside file 'named-array.raku'
300+
sub MAIN(:@n) {
301+
.raku.say for @n
302+
}
303+
304+
You can use this on the command line by repeating the named-array
305+
parameter with different values each time.
306+
307+
=begin code :lang<shell>
308+
$ raku named-array.raku --n=foo --n=23 --n=6.3 --n=3e8 --n=2+2i --n=bar
309+
"foo"
310+
IntStr.new(23, "23")
311+
RatStr.new(6.3, "6.3")
312+
NumStr.new(300000000e0, "3e8")
313+
ComplexStr.new(<2+2i>, "2+2i")
314+
"bar"
315+
=end code
316+
317+
=head2 Enumerations
318+
282319
L<C<Enumeration>|/type/Enumeration>s can be used in signatures with arguments converted
283320
automatically to its corresponding C<enum> symbol:
284321

0 commit comments

Comments
 (0)