Skip to content

Commit c29f55d

Browse files
committed
Document unit sub MAIN, index existing unit and module declarators.
Closes #1819.
1 parent 462336d commit c29f55d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

doc/Language/functions.pod6

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,20 @@ positional parameter. For example, the above program can be called with:
10481048
perl6 example.p6 1 --c=2 3 --d=4
10491049
=end code
10501050
1051+
=head2 X<Unit-scoped definition of MAIN|declarator,unit (MAIN)>
1052+
1053+
If the entire script body resides within C<MAIN>, you can use the C<unit>
1054+
declarator as follows:
1055+
1056+
unit sub MAIN( Int :$length = 24,
1057+
:file($data) where { .IO.f // die "file not found in $*CWD" } = 'file.dat',
1058+
Bool :v(:$verbose) #`( -verbose, --verbose, -v or --v ) );
1059+
1060+
# rest of script is part of MAIN
1061+
1062+
Note that this is only appropriate if you do not need a C<proto> or C<multi> definition.
1063+
1064+
10511065
=head1 sub USAGE
10521066
10531067
X<|USAGE>X<|$*USAGE>

doc/Language/syntax.pod6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ You can also assign subroutines to variables.
609609
my &f = -> { say "Hello!" } # Lambda style syntax. The & sigil indicates the variable holds a function
610610
my $f = -> { say "Hello!" } # Functions can also be put into scalars
611611
612-
=head3 Module, Class, Role, and Grammar declaration
612+
=head3 X<Module, Class, Role, and Grammar declaration|declarator,unit;declarator,module>
613613
614614
There are several types of compilation units (packages), each declared with a
615615
keyword, a name, some optional traits, and a body of functions.
@@ -622,7 +622,7 @@ keyword, a name, some optional traits, and a body of functions.
622622
623623
grammar Baz { }
624624
625-
You can declare a unit of things without explicit curly brackets.
625+
You can declare a C<unit> of things without explicit curly brackets.
626626
627627
=begin code :skip-test
628628
unit module Gar;

0 commit comments

Comments
 (0)