You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -224,7 +225,8 @@ A normal method in a subclass does not compete with multis of a parent class.
224
225
X«|only method»
225
226
=head4Only method
226
227
227
-
To explicitly state that a method is not a multi method use the C<only method> declarator.
228
+
To explicitly state that a method is not a multi method use the C<only> method
229
+
declarator.
228
230
229
231
=forcode :skip-test<compile time error>
230
232
class C {
@@ -240,8 +242,8 @@ L<Mu|/type/Mu>, which in turn is called by L<.bless|/type/Mu#method_bless>. It
240
242
is meant to set private and public attributes of a class and receives all names
241
243
attributes passed into C<.bless>. Since it is called by C<BUILDALL> the default
242
244
constructor L<.new|/type/Mu#method_new> defined in C<Mu> is the method that
243
-
invokes it. Public accessor methods are not available in C<BUILD> use private
244
-
attribute notation instead.
245
+
invokes it. Given that public accessor methods are not available in C<BUILD>,
246
+
you must use private attribute notation instead.
245
247
246
248
class C {
247
249
has $.attr;
@@ -312,15 +314,16 @@ shares the name with the attribute:
312
314
class B {
313
315
has $.i = "answer";
314
316
method m() { A.new(:$.i) }
317
+
# ^^^^ Instead of i => $.i or :i($.i)
315
318
};
316
319
my $a = B.new.m;
317
320
say $a.i; # OUTPUT: «answer»
318
321
319
-
Since C<$.i> method call is named C<i> and the attribute is named C<i>, Perl 6
322
+
Since C<$.i> method call is named C<i> and the attribute is also named C<i>, Perl 6
320
323
lets us shortcut. The same applies to C<:$var>, C<:$!private-attribute>,
321
324
C<:&attr-with-code-in-it>, and so on.
322
325
323
-
=head4trait C<is nodal>
326
+
=head3trait C<is nodal>
324
327
325
328
Marks a L<List> method to indicate to hyperoperator to not descend into inner
326
329
L<Iterables|/type/Iterable> to call this method. This trait generally isn't
@@ -340,10 +343,10 @@ Defined as:
340
343
341
344
multi sub trait_mod:<handles>(Attribute:D $target, $thunk)
342
345
343
-
The L<trait|/type/Sub#Traits>C<handles> applied to an attribute of a class will delegate all calls
344
-
to the provided method name to the method with the same name of the attribute.
345
-
The object referenced by the attribute must be initialized. A type constraint
346
-
for the object that the call is delegated to can be provided.
346
+
The L<trait|/type/Sub#Traits>C<handles> applied to an attribute of a class will
347
+
delegate all calls to the provided method name to the method with the same name
348
+
of the attribute. The object referenced by the attribute must be initialized. A
349
+
type constraint for the object that the call is delegated to can be provided.
347
350
348
351
class A { method m(){ 'A::m has been called.' } }
349
352
class B is A { method m(){ 'B::m has been called.' } }
@@ -353,11 +356,11 @@ for the object that the call is delegated to can be provided.
353
356
};
354
357
say C.new(B.new).m(); # OUTPUT: «B::m has been called.»
355
358
356
-
Instead of a method name, a C<Pair> (for renaming), a list of names orC<Pair>s, a C<Regex>
357
-
or a C<Whatever> can be provided. In the latter case existing methods, both in the class itself and
358
-
its inheritance chain, will take precedence. If even local
359
-
X«C<FALLBACK>|FALLBACK (trait handles)»s should be searched use a
360
-
C<HyperWhatever>.
359
+
Instead of a method name, a C<Pair> (for renaming), a list of names or
360
+
C<Pair>s, a C<Regex>or a C<Whatever> can be provided. In the latter case
361
+
existing methods, both in the class itself and its inheritance chain, will take
362
+
precedence. If even local X«C<FALLBACK>|FALLBACK (trait handles)»s should be
363
+
searched, use a C<HyperWhatever>.
361
364
362
365
class A {
363
366
method m1(){}
@@ -416,8 +419,8 @@ Defined as:
416
419
417
420
sub trait_mod:<is>(Mu:U $type, :$rw!)
418
421
419
-
The L<trait|/type/Sub#Traits>C<is rw> on a class will create writable accessor methods on all
420
-
public attributes of that class.
422
+
The L<trait|/type/Sub#Traits>C<is rw> on a class will create writable accessor
423
+
methods on all public attributes of that class.
421
424
422
425
class C is rw {
423
426
has $.a;
@@ -517,15 +520,16 @@ there may be performance implications, hence the pragmas.
517
520
say $s.mark
518
521
# OUTPUT: «answer»
519
522
520
-
There are little limitations what can be done inside the class fragment. One of
523
+
There are little limitations of what can be done inside the class fragment. One of
521
524
them is the redeclaration of a method or sub into a multi. Using added
522
525
attributes is not yet implemented. Please note that adding a multi candidate
523
526
that differs only in its named parameters will add that candidate behind the
524
527
already defined one and as such it won't be picked by the dispatcher.
525
528
526
529
=head3Versioning and authorship
527
530
528
-
Versioning and authorship can be applied via adverbs X«C«:ver<>»|:ver<> (class)» and X«C«:auth<>»|:auth<> (class)».
531
+
Versioning and authorship can be applied via the adverbs
532
+
X«C«:ver<>»|:ver<> (class)» and X«C«:auth<>»|:auth<> (class)».
529
533
Both take a string as argument, for C<:ver> the string is converted to a
530
534
L<Version|/type/Version> object. To query a class version and author use
531
535
C<.^ver> and C<^.auth>.
@@ -612,8 +616,8 @@ X<|Type Capture (role)>L<Type captures|/type/Signature#Type_captures> are suppor
612
616
say $c;
613
617
# OUTPUT: «C.new(a => "default")»
614
618
615
-
Parameters can have type constraints, C<where> clauses are not supported for types but can
616
-
be implemented via C<subset>s.
619
+
Parameters can have type constraints, C<where> clauses are not supported for
620
+
types but can be implemented via C<subset>s.
617
621
618
622
class A {};
619
623
class B {};
@@ -674,7 +678,8 @@ say [(75kg).^name, N(75kg).^name];
674
678
675
679
=head3Versioning and authorship
676
680
677
-
Versioning and authorship can be applied via adverbs X«C«:ver<>»|:ver<> (role)» and X«C«:auth<>»|:auth<> (role)».
681
+
Versioning and authorship can be applied via the adverbs
682
+
X«C«:ver<>»|:ver<> (role)» and X«C«:auth<>»|:auth<> (role)».
678
683
Both take a string as argument, for C<:ver> the string is converted to a
679
684
L<Version|/type/Version> object. To query a role's version and author use
680
685
C<.^ver> and C<^.auth>.
@@ -760,8 +765,8 @@ the keys.
760
765
=head3Metaclass
761
766
762
767
To test if a given type object is an C<enum>, test the meta object method
763
-
C<.HOW>forL<Metamodel::EnumHOW|/type/Metamodel::EnumHOW> or simply test again
764
-
the C<Enumeration> role.
768
+
C<.HOW>againstL<Metamodel::EnumHOW|/type/Metamodel::EnumHOW> or simply test
769
+
against the C<Enumeration> role.
765
770
766
771
enum E(<a b c>);
767
772
say E.HOW ~~ Metamodel::EnumHOW; # OUTPUT: «True»
@@ -790,19 +795,21 @@ enum object, use the coercer with the name of the enum:
790
795
A(72).pair.say; # OUTPUT: «mon => 72»
791
796
A(1000).say; # OUTPUT: «(A)»
792
797
793
-
The last example shows what happens if there is no enumpair that includes that
798
+
The last example shows what happens if there is no enum-pair that includes that
794
799
as a value.
795
800
796
801
=head2C<module>
797
802
798
-
Modules are usually one or more source files that expose Perl 6 constructs, such as classes, roles, grammars, subroutines and variables.
799
-
Modules are usually used for distributing Perl 6 code as libraries which can be used in another Perl 6 programme.
803
+
Modules are usually one or more source files that expose Perl 6 constructs,
804
+
such as classes, roles, grammars, subroutines and variables. Modules are
805
+
usually used for distributing Perl 6 code as libraries which can be used in
806
+
another Perl 6 program.
800
807
801
808
For a full explanation see L<Modules|/language/modules>.
802
809
803
810
=head3Versioning and authorship
804
811
805
-
Versioning and authorship can be applied via adverbs C«:ver<>» and C«:auth<>».
812
+
Versioning and authorship can be applied via the adverbs C«:ver<>» and C«:auth<>».
806
813
Both take a string as argument, for C<:ver> the string is converted to a
807
814
L<Version|/type/Version> object. To query a modules version and author use
808
815
C<.^ver> and C<^.auth>.
@@ -813,19 +820,23 @@ C<.^ver> and C<^.auth>.
813
820
814
821
=head2C<package>
815
822
816
-
Packages are nested namespaces of named program elements. Modules, classes and grammars are all types of package.
823
+
Packages are nested namespaces of named program elements. Modules, classes and
824
+
grammars are all types of package.
817
825
818
826
For a full explanation see L<Packages|/language/packages>.
819
827
820
828
=head2C<grammar>
821
829
822
-
Grammars are a specific type of class intended for parsing text. Grammars are composed of rules, tokens and regexes which are actually methods, since grammars are classes.
830
+
Grammars are a specific type of class intended for parsing text. Grammars are
831
+
composed of rules, tokens and regexes which are actually methods, since grammars
832
+
are classes.
823
833
824
834
For a full explanation see L<Grammars|/language/grammars>.
825
835
826
836
=head3Versioning and authorship
827
837
828
-
Versioning and authorship can be applied via adverbs X«C«:ver<>»|:ver<> (grammar)» and X«C«:auth<>»|:auth<> (grammar)».
838
+
Versioning and authorship can be applied via the adverbs
839
+
X«C«:ver<>»|:ver<> (grammar)» and X«C«:auth<>»|:auth<> (grammar)».
829
840
Both take a string as argument, for C<:ver> the string is converted to a
830
841
L<Version|/type/Version> object. To query a grammars version and author use
831
842
C<.^ver> and C<^.auth>.
@@ -847,6 +858,7 @@ will be checked against the given code object.
847
858
# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $i; expected Positive but got Int (-42)»
848
859
849
860
Subsets can be used in signatures, e.g. by typing the output:
861
+
850
862
subset Foo of List where (Int,Str);
851
863
sub a($a, $b, --> Foo) { $a, $b }
852
864
# Only a List with the first element being an Int and the second a Str will pass the type check.
@@ -864,7 +876,8 @@ but a name is neither needed nor desirable.
864
876
g([A, C]);
865
877
# OUTPUT: «[A C]»
866
878
867
-
Subsets can be used to check types dynamically, what can be useful in conjunction with L<require|/language/modules#require>.
879
+
Subsets can be used to check types dynamically, which can be useful in conjunction
0 commit comments