Skip to content

Commit fd2872a

Browse files
committed
Revises Signature
:tick: Reflow :tick: Eliminates Unneeded Caps :tick: Eliminates uneeded categories refs #1410
1 parent 37b2a4c commit fd2872a

File tree

1 file changed

+65
-56
lines changed

1 file changed

+65
-56
lines changed

doc/Type/Signature.pod6

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ you need to pass to the code or function in order to call it.
1313
Passing arguments to a signature I<binds> the arguments, contained in
1414
a L<Capture>, to the signature.
1515
16-
X<|signature literal (Signature)>
17-
X<|:() (Signature)>
18-
=head1 Signature Literals
16+
X<|signature literal>
17+
X<|:()>
18+
=head1 Signature literals
1919
2020
Signatures appear inside parentheses after L<subroutine|/type/Sub> and
2121
L<method|/type/Method> names, on blocks after a C<< -> >> or C<< <-> >> arrow,
@@ -79,7 +79,7 @@ keys of the Hash.
7979
say %h ~~ :(:$left, :$right);
8080
# OUTPUT: «True␤»
8181
82-
=head2 Parameter Separators
82+
=head2 Parameter separators
8383
8484
A signature consists of zero or more I<L<parameters|Parameter>>, separated by
8585
commas.
@@ -102,7 +102,7 @@ is bound to.
102102
}
103103
say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
104104
105-
X<|type constraint (Signature)>
105+
X<|type constraint>
106106
X<|Constraint>
107107
=head2 Type constraints
108108
@@ -128,9 +128,9 @@ subset is based, in this case C<Int>. If it fails, a C<Type check> error is
128128
produced. Once that filter is cleared, the constraint that defined the subset is
129129
checked, producing a C<I<Constraint> type check> error if it fails.
130130
131-
X<|anonymous arguments (Signature)> Anonymous arguments are fine too, if you
132-
don't actually need to refer to a parameter by name, for instance to distinguish
133-
between different signatures in a
131+
X<|anonymous arguments>
132+
Anonymous arguments are fine too, if you don't actually need to refer to a
133+
parameter by name, for instance to distinguish between different signatures in a
134134
L<multi|/language/functions#index-entry-declarator_multi-Multi-dispatch> or to
135135
check the signature of a L<Callable>.
136136
@@ -140,7 +140,7 @@ check the signature of a L<Callable>.
140140
141141
Type constraints may also be L<type captures|/type/Signature#Type_Captures>.
142142
143-
X<|where clause (Signature)>
143+
X<|where clause>
144144
In addition to those I<nominal> types, additional constraints can
145145
be placed on parameters in the form of code blocks which must return
146146
a true value to pass the type check
@@ -193,7 +193,7 @@ the C<where>-clause inside the sub-signature.
193193
# foo 2, 3;
194194
# OUTPUT: «Constraint type check failed in binding to parameter '$b'…»
195195
196-
=head3 Constraining Optional Arguments
196+
=head3 Constraining optional arguments
197197
198198
L<Optional arguments|#Optional_and_Mandatory_Parameters> can have constraints,
199199
too. Any C<where> clause on any parameter will be executed, even if it's
@@ -202,7 +202,7 @@ against undefined values within the C<where> clause.
202202
203203
sub f(Int $a, UInt $i? where { !$i.defined or $i > 5 } ) { ... }
204204
205-
=head3 Constraining Slurpy Arguments
205+
=head3 Constraining slurpy arguments
206206
207207
L<Slurpy arguments|#Slurpy_(A.K.A._Variadic)_Parameters> can not have type
208208
constraints. A C<where>-clause in conjunction with a L<Junction|/type/Junction>
@@ -214,7 +214,7 @@ can be used to that effect.
214214
CATCH { default { say .^name, ' ==> ', .Str } }
215215
# OUTPUT: «[42]␤Constraint type check failed in binding to parameter '@a' ...»
216216
217-
=head3 Constraining named Arguments
217+
=head3 Constraining named arguments
218218
219219
Constraints against L<Named arguments|#Positional_vs._Named> apply to the value
220220
part of the L<colon-pair|/type/Pair>.
@@ -225,8 +225,11 @@ part of the L<colon-pair|/type/Pair>.
225225
# OUTPUT: «X::TypeCheck::Binding::Parameter ==> Type check failed in
226226
# binding to parameter '$i'; expected Int but got Str ("forty-two")␤»
227227
228-
=head3 X<Constraining Defined and Undefined Values|
229-
type constraint,:D;type constraint,:U;type constraint,:_>
228+
|
229+
X<|type constraint,:D>
230+
X<|type constraint,:U>
231+
X<|type constraint,:_>
232+
=head3 Constraining defined and undefined values
230233
231234
Normally, a type constraint only checks whether the value of the parameter is of
232235
the correct type. Crucially, both I<object instances> and I<type objects> will
@@ -254,10 +257,10 @@ and type objects (C<Int>). Consider the following code:
254257
# (Str:D $: *%_)»
255258
say limit-lines "a \n b", Int # Always returns the max number of lines
256259
257-
Here we really only want to deal with string instances, not
258-
type objects. To do this, we can use the C<:D> type constraint. This constraint
259-
checks that the value passed is an I<object instance>, in a similar fashion to calling
260-
its L<DEFINITE|/language/mop#DEFINITE> method.
260+
Here we really only want to deal with string instances, not type objects. To do
261+
this, we can use the C<:D> type constraint. This constraint checks that the
262+
value passed is an I<object instance>, in a similar fashion to calling its
263+
L<DEFINITE|/language/mop#DEFINITE> method.
261264
262265
To warm up, let's apply C<:D> to the right-hand side of our humble C<Int> example:
263266
@@ -349,7 +352,7 @@ a type object, which would fail the definiteness constraint.
349352
sub divide (Int:D :$a = 2, Int:D :$b!) { say $a/$b }
350353
divide :1a, :2b; # OUTPUT: «0.5␤»
351354
352-
=head3 X«Constraining signatures of Callables|Callable (constrain)»
355+
=head3 Constraining signatures of C<Callable>s
353356
354357
A L<Callable> parameter can be constrained by its signature, by specifying
355358
a L<Signature> literal right after the parameter (no whitespace allowed):
@@ -368,14 +371,15 @@ others, you need to use the long version:
368371
# f(&g); # Constraint type check failed
369372
f(&h); # OUTPUT: «ten10␤»
370373
371-
=head3 X«Constraining Return Types|-->;returns»
374+
=head3 Constraining return types
372375
373-
There are multiple ways to constrain return types on a L<Routine|/type/Routine>. All versions below
374-
are currently valid and will force a type check on successful execution of a routine.
376+
There are multiple ways to constrain return types on a L<Routine|/type/Routine>.
377+
All versions below are currently valid and will force a type check on successful
378+
execution of a routine.
375379
376-
L<C<Nil>|/type/Nil> and L<C<Failure>|/type/Failure> are always allowed as return types,
377-
regardless of any type constraint. This allows L<Failure|/type/Failure> to be returned
378-
and passed on down the call chain.
380+
L<C<Nil>|/type/Nil> and L<C<Failure>|/type/Failure> are always allowed as return
381+
types, regardless of any type constraint. This allows L<Failure|/type/Failure>
382+
to be returned and passed on down the call chain.
379383
380384
sub foo(--> Int) { Nil };
381385
say foo.perl; # OUTPUT: «Nil␤»
@@ -449,7 +453,7 @@ except the C<$var> is a definition for a routine.
449453
=for code :skip-test
450454
my 42 sub bad-answer {}; # This will fail.
451455
452-
=head3 X<Coercion Type|coercion type (signature)>
456+
=head3 X<Coercion type>
453457
454458
To accept one type but coerce it automatically to another, use the
455459
accepted type as an argument to the target type. If the accepted type is
@@ -489,9 +493,13 @@ for 2,4, *² … 256 -> $a {
489493
# 256² is 5 figures long␤»
490494
=end code
491495
492-
In this example, coercing the return type to C<String> allows us to directly apply string methods, such as the number of characters.
496+
In this example, coercing the return type to C<String> allows us to directly
497+
apply string methods, such as the number of characters.
493498
494-
=head2 X<Slurpy (A.K.A. Variadic) Parameters|parameter,*@;parameter,*%,slurpy argument (Signature)>
499+
X<|parameter,*@>
500+
X<|parameter,*%>
501+
X<|slurpy argument>
502+
=head2 Slurpy (A.K.A. variadic) parameters
495503
496504
A function is X<variadic> if it can take a varying number of arguments; that is,
497505
its arity is not fixed. Therefore, optional, named, and slurpy parameters are
@@ -535,7 +543,7 @@ Slurpy parameters have special behaviors when combined with some
535543
L<traits and modifiers|#Parameter_Traits_and_Modifiers>,
536544
as described in L<the section on slurpy array parameters|/type/Signature#Types_of_Slurpy_Array_Parameters>.
537545
538-
=head2 Types of Slurpy Array Parameters
546+
=head2 Types of slurpy array parameters
539547
540548
There are three variations to slurpy array parameters.
541549
@@ -549,7 +557,7 @@ Each will be described in detail in the next few sections. As the difference
549557
between each is a bit nuanced, examples are provided for each to demonstrate how
550558
each slurpy convention varies from the others.
551559
552-
=head3 Flattened Slurpy
560+
=head3 Flattened slurpy
553561
554562
Slurpy parameters declared with one asterisk will flatten arguments by
555563
dissolving one or more layers of bare L<Iterable|/type/Iterable>s.
@@ -568,10 +576,11 @@ a(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]»
568576
A single asterisk slurpy flattens all given iterables, effectively hoisting any
569577
object created with commas up to the top level.
570578
571-
=head3 X<Unflattened Slurpy|parameter, **@>
579+
=head3 X<Unflattened slurpy|parameter, **@>
572580
573-
Slurpy parameters declared with two stars do not flatten any L<Iterable|/type/Iterable> arguments
574-
within the list, but keep the arguments more or less as-is:
581+
Slurpy parameters declared with two stars do not flatten any
582+
L<Iterable|/type/Iterable> arguments within the list, but keep the arguments
583+
more or less as-is:
575584
576585
=begin code
577586
my @array = <a b c>;
@@ -587,14 +596,15 @@ b(($_ for 1, 2, 3)); # OUTPUT: «[(1, 2, 3),]␤»
587596
The double asterisk slurpy hides the nested comma objects and leaves them as-is
588597
in the slurpy array.
589598
590-
=head3 Single Argument Rule Slurpy
591-
X<|+ (Single Argument Rule Slurpy)>
599+
X<|+ (Single argument rule slurpy)>
600+
=head3 Single argument rule slurpy
601+
592602
593603
A slurpy parameter created using a plus engages the I<"single argument rule">,
594604
which decides how to handle the slurpy argument based upon context. Basically,
595-
if only a single argument is passed and that argument is L<Iterable|/type/Iterable>, that argument
596-
is used to fill the slurpy parameter array. In any other case, C<+@> works like
597-
C<**@>.
605+
if only a single argument is passed and that argument is
606+
L<Iterable|/type/Iterable>, that argument is used to fill the slurpy parameter
607+
array. In any other case, C<+@> works like C<**@>.
598608
599609
=begin code
600610
my @array = <a b c>;
@@ -609,10 +619,10 @@ c(($_ for 1, 2, 3)); # OUTPUT: «[1, 2, 3]␤»
609619
610620
For additional discussion and examples, see L<Slurpy Conventions for Functions|/language/functions#Slurpy_Conventions>.
611621
612-
=head2 Type Captures
613-
X<|Type Capture (signature)>
622+
X<|Type capture>
623+
=head2 Type captures
614624
615-
Type Captures allow deferring the specification of a type constraint to the time
625+
Type captures allow deferring the specification of a type constraint to the time
616626
the function is called. They allow referring to a type both in the signature and
617627
the function body.
618628
@@ -630,9 +640,9 @@ the function body.
630640
my &s = f(10, 2, Int.new / Int.new);
631641
say s(2); # 10 / 2 * 2 == 10
632642
633-
X<|positional argument (Signature)>
634-
X<|named argument (Signature)>
635-
=head2 Positional vs. Named Arguments
643+
X<|positional argument>
644+
X<|named argument>
645+
=head2 Positional vs. named arguments
636646
637647
An argument can be I<positional> or I<named>. All arguments are positional,
638648
except slurpy hash and arguments marked with a leading colon C<:>.
@@ -664,8 +674,8 @@ variable name:
664674
sub named(:official($private)) { "Official business!" if $private }
665675
named :official;
666676
667-
X<|aliases (Signature)>
668-
=head2 Argument Aliases
677+
X<|aliases>
678+
=head2 Argument aliases
669679
The L<colon-pair|/type/Pair> syntax can be used to provide aliases for arguments:
670680
671681
sub alias-named(:color(:$colour), :type(:class($kind))) {
@@ -709,8 +719,8 @@ before slipping.
709719
say C.new(|%h.Map);
710720
# OUTPUT: «C.new(x => 5, y => 20, z => [1, 2])␤»
711721
712-
X<|optional argument (Signature)>
713-
=head2 Optional and Mandatory Parameters
722+
X<|optional argument>
723+
=head2 Optional and mandatory arguments
714724
715725
Positional parameters are mandatory by default, and can be made optional
716726
with a default value or a trailing question mark:
@@ -719,7 +729,7 @@ with a default value or a trailing question mark:
719729
$ = :($base = 10); # optional parameter, default value 10
720730
$ = :(Int $x?); # optional parameter, default is the Int type object
721731
722-
X<|mandatory named argument (Signature)>
732+
X<|mandatory named argument>
723733
Named parameters are optional by default, and can be made mandatory with a
724734
trailing exclamation mark:
725735
@@ -733,14 +743,14 @@ notionally) computed anew for each call
733743
$ = :($goal, $accuracy = $goal / 100);
734744
$ = :(:$excludes = ['.', '..']); # a new Array for every call
735745
736-
=head2 Dynamic Variables
746+
=head2 Dynamic variables
737747
738748
L<Dynamic variables|/language/variables#The_*_Twigil> are allowed in signatures
739749
although they don't provide special behaviour because argument binding does
740750
connect two scopes anyway.
741751
742-
X<|destructuring arguments (Signature)>
743-
=head2 Destructuring Parameters
752+
X<|destructuring arguments>
753+
=head2 Destructuring arguments
744754
745755
Parameters can be followed by a sub-signature in parentheses, which will
746756
destructure the argument given. The destructuring of a list is just its
@@ -787,8 +797,7 @@ name in parentheses.
787797
foo(42, "answer");
788798
# OUTPUT: «called with \(42, "answer")␤»
789799
790-
X<|Long Names>
791-
=head2 Long Names
800+
=head2 X<Long names>
792801
793802
To exclude certain parameters from being considered in multiple dispatch,
794803
separate them with a double semi-colon.
@@ -797,7 +806,7 @@ separate them with a double semi-colon.
797806
f(10, 'answer');
798807
# OUTPUT: «10, answer, Any␤»
799808
800-
=head2 X<Capture Parameters|parameter,|>
809+
=head2 X<Capture parameters|parameter,|>
801810
802811
Prefixing a parameter with a vertical bar C<|> makes the parameter a
803812
L<C<Capture>>, using up all the remaining positional and named
@@ -816,7 +825,7 @@ operator C<|>.
816825
b(42, "answer");
817826
# OUTPUT: «Capture␤Int Str␤»
818827
819-
=head2 Parameter Traits and Modifiers
828+
=head2 Parameter traits and modifiers
820829
821830
By default, parameters are bound to their argument and marked as
822831
read-only. One can change that with traits on the parameter.

0 commit comments

Comments
 (0)