Skip to content

Commit

Permalink
Merge pull request #2382 from uzluisf/master
Browse files Browse the repository at this point in the history
Add minor fixes, rephrase sentences and reflow text
  • Loading branch information
uzluisf committed Oct 14, 2018
2 parents 6f2d2af + 566febe commit d1e077c
Showing 1 changed file with 50 additions and 37 deletions.
87 changes: 50 additions & 37 deletions doc/Language/typesystem.pod6
Expand Up @@ -107,7 +107,7 @@ L<MOP|/language/mop>.
# OUTPUT: «oioioioioioioioioioi‽␤»
Perl 6 provides methods defined in L<Cool|/type/Cool> to convert to a target
type before applying further operations. Most build-in types descend from
type before applying further operations. Most built-in types descend from
C<Cool> and as such may provide implicit coercion that may be undesired. It is
the responsibility of the user to care about trap-free usage of those
methods.
Expand Down Expand Up @@ -146,10 +146,11 @@ can be provided with the declaration of attributes or in constructors. It's the
responsibility of the L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW> to know
how to run them. This is the only magic part of building objects in Perl 6. The
default parent type is C<Any> which in turn inherits from C<Mu>. The latter
provides the default constructor C<.new>. It's name is by convention and does
not carry any special meaning nor is C<.new> treated in any special way.
provides the default constructor C<.new> which is named like this by convention.
Aside from this, C<.new> does not carry any special meaning nor is treated in a
special way.
For more information how to use classes see the L<classtut|/language/classtut>
For more information how to use classes see the L<Classes and objects|/language/classtut>
tutorial.
=head3 Mixins
Expand All @@ -172,8 +173,8 @@ that is mixed in.
=head4 Metaclass
To test if a given type object is a class test the meta object method C<.HOW>
for L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW>.
To test if a given type object is a class, test the meta object method C<.HOW>
against L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW>.
class C {};
say C.HOW ~~ Metamodel::ClassHOW;
Expand Down Expand Up @@ -224,7 +225,8 @@ A normal method in a subclass does not compete with multis of a parent class.
X«|only method»
=head4 Only method
To explicitly state that a method is not a multi method use the C<only method> declarator.
To explicitly state that a method is not a multi method use the C<only> method
declarator.
=for code :skip-test<compile time error>
class C {
Expand All @@ -240,8 +242,8 @@ L<Mu|/type/Mu>, which in turn is called by L<.bless|/type/Mu#method_bless>. It
is meant to set private and public attributes of a class and receives all names
attributes passed into C<.bless>. Since it is called by C<BUILDALL> the default
constructor L<.new|/type/Mu#method_new> defined in C<Mu> is the method that
invokes it. Public accessor methods are not available in C<BUILD> use private
attribute notation instead.
invokes it. Given that public accessor methods are not available in C<BUILD>,
you must use private attribute notation instead.
class C {
has $.attr;
Expand Down Expand Up @@ -312,15 +314,16 @@ shares the name with the attribute:
class B {
has $.i = "answer";
method m() { A.new(:$.i) }
# ^^^^ Instead of i => $.i or :i($.i)
};
my $a = B.new.m;
say $a.i; # OUTPUT: «answer␤»
Since C<$.i> method call is named C<i> and the attribute is named C<i>, Perl 6
Since C<$.i> method call is named C<i> and the attribute is also named C<i>, Perl 6
lets us shortcut. The same applies to C<:$var>, C<:$!private-attribute>,
C<:&attr-with-code-in-it>, and so on.
=head4 trait C<is nodal>
=head3 trait C<is nodal>
Marks a L<List> method to indicate to hyperoperator to not descend into inner
L<Iterables|/type/Iterable> to call this method. This trait generally isn't
Expand All @@ -340,10 +343,10 @@ Defined as:
multi sub trait_mod:<handles>(Attribute:D $target, $thunk)
The L<trait|/type/Sub#Traits> C<handles> applied to an attribute of a class will delegate all calls
to the provided method name to the method with the same name of the attribute.
The object referenced by the attribute must be initialized. A type constraint
for the object that the call is delegated to can be provided.
The L<trait|/type/Sub#Traits> C<handles> applied to an attribute of a class will
delegate all calls to the provided method name to the method with the same name
of the attribute. The object referenced by the attribute must be initialized. A
type constraint for the object that the call is delegated to can be provided.
class A { method m(){ 'A::m has been called.' } }
class B is A { method m(){ 'B::m has been called.' } }
Expand All @@ -353,11 +356,11 @@ for the object that the call is delegated to can be provided.
};
say C.new(B.new).m(); # OUTPUT: «B::m has been called.␤»
Instead of a method name, a C<Pair> (for renaming), a list of names or C<Pair>s, a C<Regex>
or a C<Whatever> can be provided. In the latter case existing methods, both in the class itself and
its inheritance chain, will take precedence. If even local
X«C<FALLBACK>|FALLBACK (trait handles)»s should be searched use a
C<HyperWhatever>.
Instead of a method name, a C<Pair> (for renaming), a list of names or
C<Pair>s, a C<Regex> or a C<Whatever> can be provided. In the latter case
existing methods, both in the class itself and its inheritance chain, will take
precedence. If even local X«C<FALLBACK>|FALLBACK (trait handles)»s should be
searched, use a C<HyperWhatever>.
class A {
method m1(){}
Expand Down Expand Up @@ -416,8 +419,8 @@ Defined as:
sub trait_mod:<is>(Mu:U $type, :$rw!)
The L<trait|/type/Sub#Traits> C<is rw> on a class will create writable accessor methods on all
public attributes of that class.
The L<trait|/type/Sub#Traits> C<is rw> on a class will create writable accessor
methods on all public attributes of that class.
class C is rw {
has $.a;
Expand Down Expand Up @@ -517,15 +520,16 @@ there may be performance implications, hence the pragmas.
say $s.mark
# OUTPUT: «answer␤»
There are little limitations what can be done inside the class fragment. One of
There are little limitations of what can be done inside the class fragment. One of
them is the redeclaration of a method or sub into a multi. Using added
attributes is not yet implemented. Please note that adding a multi candidate
that differs only in its named parameters will add that candidate behind the
already defined one and as such it won't be picked by the dispatcher.
=head3 Versioning and authorship
Versioning and authorship can be applied via adverbs X«C«:ver<>»|:ver<> (class)» and X«C«:auth<>»|:auth<> (class)».
Versioning and authorship can be applied via the adverbs
X«C«:ver<>»|:ver<> (class)» and X«C«:auth<>»|:auth<> (class)».
Both take a string as argument, for C<:ver> the string is converted to a
L<Version|/type/Version> object. To query a class version and author use
C<.^ver> and C<^.auth>.
Expand Down Expand Up @@ -612,8 +616,8 @@ X<|Type Capture (role)>L<Type captures|/type/Signature#Type_captures> are suppor
say $c;
# OUTPUT: «C.new(a => "default")␤»
Parameters can have type constraints, C<where> clauses are not supported for types but can
be implemented via C<subset>s.
Parameters can have type constraints, C<where> clauses are not supported for
types but can be implemented via C<subset>s.
class A {};
class B {};
Expand Down Expand Up @@ -674,7 +678,8 @@ say [(75kg).^name, N(75kg).^name];
=head3 Versioning and authorship
Versioning and authorship can be applied via adverbs X«C«:ver<>»|:ver<> (role)» and X«C«:auth<>»|:auth<> (role)».
Versioning and authorship can be applied via the adverbs
X«C«:ver<>»|:ver<> (role)» and X«C«:auth<>»|:auth<> (role)».
Both take a string as argument, for C<:ver> the string is converted to a
L<Version|/type/Version> object. To query a role's version and author use
C<.^ver> and C<^.auth>.
Expand Down Expand Up @@ -760,8 +765,8 @@ the keys.
=head3 Metaclass
To test if a given type object is an C<enum>, test the meta object method
C<.HOW> for L<Metamodel::EnumHOW|/type/Metamodel::EnumHOW> or simply test again
the C<Enumeration> role.
C<.HOW> against L<Metamodel::EnumHOW|/type/Metamodel::EnumHOW> or simply test
against the C<Enumeration> role.
enum E(<a b c>);
say E.HOW ~~ Metamodel::EnumHOW; # OUTPUT: «True␤»
Expand Down Expand Up @@ -790,19 +795,21 @@ enum object, use the coercer with the name of the enum:
A(72).pair.say; # OUTPUT: «mon => 72␤»
A(1000).say; # OUTPUT: «(A)␤»
The last example shows what happens if there is no enumpair that includes that
The last example shows what happens if there is no enum-pair that includes that
as a value.
=head2 C<module>
Modules are usually one or more source files that expose Perl 6 constructs, such as classes, roles, grammars, subroutines and variables.
Modules are usually used for distributing Perl 6 code as libraries which can be used in another Perl 6 programme.
Modules are usually one or more source files that expose Perl 6 constructs,
such as classes, roles, grammars, subroutines and variables. Modules are
usually used for distributing Perl 6 code as libraries which can be used in
another Perl 6 program.
For a full explanation see L<Modules|/language/modules>.
=head3 Versioning and authorship
Versioning and authorship can be applied via adverbs C«:ver<>» and C«:auth<>».
Versioning and authorship can be applied via the adverbs C«:ver<>» and C«:auth<>».
Both take a string as argument, for C<:ver> the string is converted to a
L<Version|/type/Version> object. To query a modules version and author use
C<.^ver> and C<^.auth>.
Expand All @@ -813,19 +820,23 @@ C<.^ver> and C<^.auth>.
=head2 C<package>
Packages are nested namespaces of named program elements. Modules, classes and grammars are all types of package.
Packages are nested namespaces of named program elements. Modules, classes and
grammars are all types of package.
For a full explanation see L<Packages|/language/packages>.
=head2 C<grammar>
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.
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.
For a full explanation see L<Grammars|/language/grammars>.
=head3 Versioning and authorship
Versioning and authorship can be applied via adverbs X«C«:ver<>»|:ver<> (grammar)» and X«C«:auth<>»|:auth<> (grammar)».
Versioning and authorship can be applied via the adverbs
X«C«:ver<>»|:ver<> (grammar)» and X«C«:auth<>»|:auth<> (grammar)».
Both take a string as argument, for C<:ver> the string is converted to a
L<Version|/type/Version> object. To query a grammars version and author use
C<.^ver> and C<^.auth>.
Expand All @@ -847,6 +858,7 @@ will be checked against the given code object.
# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $i; expected Positive but got Int (-42)␤»
Subsets can be used in signatures, e.g. by typing the output:
subset Foo of List where (Int,Str);
sub a($a, $b, --> Foo) { $a, $b }
# Only a List with the first element being an Int and the second a Str will pass the type check.
Expand All @@ -864,7 +876,8 @@ but a name is neither needed nor desirable.
g([A, C]);
# OUTPUT: «[A C]␤»
Subsets can be used to check types dynamically, what can be useful in conjunction with L<require|/language/modules#require>.
Subsets can be used to check types dynamically, which can be useful in conjunction
with L<require|/language/modules#require>.
X<|dynamic subset>
=for code
Expand Down

0 comments on commit d1e077c

Please sign in to comment.