Skip to content

Commit d1e077c

Browse files
authored
Merge pull request #2382 from uzluisf/master
Add minor fixes, rephrase sentences and reflow text
2 parents 6f2d2af + 566febe commit d1e077c

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

doc/Language/typesystem.pod6

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ L<MOP|/language/mop>.
107107
# OUTPUT: «oioioioioioioioioioi‽␤»
108108
109109
Perl 6 provides methods defined in L<Cool|/type/Cool> to convert to a target
110-
type before applying further operations. Most build-in types descend from
110+
type before applying further operations. Most built-in types descend from
111111
C<Cool> and as such may provide implicit coercion that may be undesired. It is
112112
the responsibility of the user to care about trap-free usage of those
113113
methods.
@@ -146,10 +146,11 @@ can be provided with the declaration of attributes or in constructors. It's the
146146
responsibility of the L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW> to know
147147
how to run them. This is the only magic part of building objects in Perl 6. The
148148
default parent type is C<Any> which in turn inherits from C<Mu>. The latter
149-
provides the default constructor C<.new>. It's name is by convention and does
150-
not carry any special meaning nor is C<.new> treated in any special way.
149+
provides the default constructor C<.new> which is named like this by convention.
150+
Aside from this, C<.new> does not carry any special meaning nor is treated in a
151+
special way.
151152
152-
For more information how to use classes see the L<classtut|/language/classtut>
153+
For more information how to use classes see the L<Classes and objects|/language/classtut>
153154
tutorial.
154155
155156
=head3 Mixins
@@ -172,8 +173,8 @@ that is mixed in.
172173
173174
=head4 Metaclass
174175
175-
To test if a given type object is a class test the meta object method C<.HOW>
176-
for L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW>.
176+
To test if a given type object is a class, test the meta object method C<.HOW>
177+
against L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW>.
177178
178179
class C {};
179180
say C.HOW ~~ Metamodel::ClassHOW;
@@ -224,7 +225,8 @@ A normal method in a subclass does not compete with multis of a parent class.
224225
X«|only method»
225226
=head4 Only method
226227
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.
228230
229231
=for code :skip-test<compile time error>
230232
class C {
@@ -240,8 +242,8 @@ L<Mu|/type/Mu>, which in turn is called by L<.bless|/type/Mu#method_bless>. It
240242
is meant to set private and public attributes of a class and receives all names
241243
attributes passed into C<.bless>. Since it is called by C<BUILDALL> the default
242244
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.
245247
246248
class C {
247249
has $.attr;
@@ -312,15 +314,16 @@ shares the name with the attribute:
312314
class B {
313315
has $.i = "answer";
314316
method m() { A.new(:$.i) }
317+
# ^^^^ Instead of i => $.i or :i($.i)
315318
};
316319
my $a = B.new.m;
317320
say $a.i; # OUTPUT: «answer␤»
318321
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
320323
lets us shortcut. The same applies to C<:$var>, C<:$!private-attribute>,
321324
C<:&attr-with-code-in-it>, and so on.
322325
323-
=head4 trait C<is nodal>
326+
=head3 trait C<is nodal>
324327
325328
Marks a L<List> method to indicate to hyperoperator to not descend into inner
326329
L<Iterables|/type/Iterable> to call this method. This trait generally isn't
@@ -340,10 +343,10 @@ Defined as:
340343
341344
multi sub trait_mod:<handles>(Attribute:D $target, $thunk)
342345
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.
347350
348351
class A { method m(){ 'A::m has been called.' } }
349352
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.
353356
};
354357
say C.new(B.new).m(); # OUTPUT: «B::m has been called.␤»
355358
356-
Instead of a method name, a C<Pair> (for renaming), a list of names or C<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>.
361364
362365
class A {
363366
method m1(){}
@@ -416,8 +419,8 @@ Defined as:
416419
417420
sub trait_mod:<is>(Mu:U $type, :$rw!)
418421
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.
421424
422425
class C is rw {
423426
has $.a;
@@ -517,15 +520,16 @@ there may be performance implications, hence the pragmas.
517520
say $s.mark
518521
# OUTPUT: «answer␤»
519522
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
521524
them is the redeclaration of a method or sub into a multi. Using added
522525
attributes is not yet implemented. Please note that adding a multi candidate
523526
that differs only in its named parameters will add that candidate behind the
524527
already defined one and as such it won't be picked by the dispatcher.
525528
526529
=head3 Versioning and authorship
527530
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)».
529533
Both take a string as argument, for C<:ver> the string is converted to a
530534
L<Version|/type/Version> object. To query a class version and author use
531535
C<.^ver> and C<^.auth>.
@@ -612,8 +616,8 @@ X<|Type Capture (role)>L<Type captures|/type/Signature#Type_captures> are suppor
612616
say $c;
613617
# OUTPUT: «C.new(a => "default")␤»
614618
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.
617621
618622
class A {};
619623
class B {};
@@ -674,7 +678,8 @@ say [(75kg).^name, N(75kg).^name];
674678
675679
=head3 Versioning and authorship
676680
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)».
678683
Both take a string as argument, for C<:ver> the string is converted to a
679684
L<Version|/type/Version> object. To query a role's version and author use
680685
C<.^ver> and C<^.auth>.
@@ -760,8 +765,8 @@ the keys.
760765
=head3 Metaclass
761766
762767
To test if a given type object is an C<enum>, test the meta object method
763-
C<.HOW> for L<Metamodel::EnumHOW|/type/Metamodel::EnumHOW> or simply test again
764-
the C<Enumeration> role.
768+
C<.HOW> against L<Metamodel::EnumHOW|/type/Metamodel::EnumHOW> or simply test
769+
against the C<Enumeration> role.
765770
766771
enum E(<a b c>);
767772
say E.HOW ~~ Metamodel::EnumHOW; # OUTPUT: «True␤»
@@ -790,19 +795,21 @@ enum object, use the coercer with the name of the enum:
790795
A(72).pair.say; # OUTPUT: «mon => 72␤»
791796
A(1000).say; # OUTPUT: «(A)␤»
792797
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
794799
as a value.
795800
796801
=head2 C<module>
797802
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.
800807
801808
For a full explanation see L<Modules|/language/modules>.
802809
803810
=head3 Versioning and authorship
804811
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<>».
806813
Both take a string as argument, for C<:ver> the string is converted to a
807814
L<Version|/type/Version> object. To query a modules version and author use
808815
C<.^ver> and C<^.auth>.
@@ -813,19 +820,23 @@ C<.^ver> and C<^.auth>.
813820
814821
=head2 C<package>
815822
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.
817825
818826
For a full explanation see L<Packages|/language/packages>.
819827
820828
=head2 C<grammar>
821829
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.
823833
824834
For a full explanation see L<Grammars|/language/grammars>.
825835
826836
=head3 Versioning and authorship
827837
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)».
829840
Both take a string as argument, for C<:ver> the string is converted to a
830841
L<Version|/type/Version> object. To query a grammars version and author use
831842
C<.^ver> and C<^.auth>.
@@ -847,6 +858,7 @@ will be checked against the given code object.
847858
# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $i; expected Positive but got Int (-42)␤»
848859
849860
Subsets can be used in signatures, e.g. by typing the output:
861+
850862
subset Foo of List where (Int,Str);
851863
sub a($a, $b, --> Foo) { $a, $b }
852864
# 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.
864876
g([A, C]);
865877
# OUTPUT: «[A C]␤»
866878
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
880+
with L<require|/language/modules#require>.
868881
X<|dynamic subset>
869882
870883
=for code

0 commit comments

Comments
 (0)