Skip to content

Commit

Permalink
Merge pull request #2366 from uzluisf/master
Browse files Browse the repository at this point in the history
Rephase sentence and fix minor typo
  • Loading branch information
JJ committed Oct 8, 2018
2 parents 757bdf9 + ef85fe0 commit f759c7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
9 changes: 5 additions & 4 deletions doc/Language/functions.pod6
Expand Up @@ -177,14 +177,15 @@ one to skip commas between named arguments.
=head2 Return values
Any C<Block> or C<Routine> will provide the value of its last expression as a return value
to the caller. If L<return|/language/control#return> or
L<return-rw|/language/control#return-rw> are called their parameter, if any,
to the caller. If either L<return|/language/control#return> or
L<return-rw|/language/control#return-rw> is called, then its parameter, if any,
will become the return value. The default return value is L<Nil|/type/Nil>.
sub a { 42 };
sub b { say a };
b;
# OUTPUT: «42␤»
sub c { };
b; # OUTPUT: «42␤»
say c; # OUTPUT: «Nil␤»
Multiple return values are returned as a list or by creating a
L<Capture|/type/Capture>. Destructuring can be used to untangle multiple return
Expand Down
19 changes: 10 additions & 9 deletions doc/Type/Signature.pod6
Expand Up @@ -126,7 +126,7 @@ Please note that in the code above type constraints are enforced at two
different levels: the first level checks if it belongs to the type in which the
subset is based, in this case C<Int>. If it fails, a C<Type check> error is
produced. Once that filter is cleared, the constraint that defined the subset is
checked, producing a C<I<Constraint> type check> error if it fails.
checked, producing a C<Constraint type check> error if it fails.
X<|anonymous arguments>
Anonymous arguments are fine too, if you don't actually need to refer to a
Expand Down Expand Up @@ -200,7 +200,7 @@ too. Any C<where> clause on any parameter will be executed, even if it's
optional and not provided by the caller. In that case you may have to guard
against undefined values within the C<where> clause.
sub f(Int $a, UInt $i? where { !$i.defined or $i > 5 } ) { ... }
sub f(Int $a, UInt $i? where { !$i.defined or $i > 5 }) { ... }
=head3 Constraining slurpy arguments
Expand Down Expand Up @@ -255,7 +255,7 @@ and type objects (C<Int>). Consider the following code:
# (Str:D $: :$count!, *%_)
# (Str:D $: $limit, *%_)
# (Str:D $: *%_)»
say limit-lines "a \n b", Int # Always returns the max number of lines
say limit-lines "a \n b", Int; # Always returns the max number of lines
Here we really only want to deal with string instances, not type objects. To do
this, we can use the C<:D> type constraint. This constraint checks that the
Expand Down Expand Up @@ -297,11 +297,10 @@ Here's a more practical example:
sub can-turn-into(Str $string, Any:U $type) {
return so $string.$type;
}
say can-turn-into("3", Int);
say can-turn-into("6.5", Int);
say can-turn-into("6.5", Num);
say can-turn-into("a string", Num);
# OUTPUT: True True True False
say can-turn-into("3", Int); # OUTPUT: «True␤»
say can-turn-into("6.5", Int); # OUTPUT: «True␤»
say can-turn-into("6.5", Num); # OUTPUT: «True␤»
say can-turn-into("a string", Num); # OUTPUT: «False␤»
Calling C<can-turn-into> with an object instance as its second parameter
will yield a constraint violation as intended:
Expand Down Expand Up @@ -331,6 +330,8 @@ known collectively as I<type smileys>:
say Foo ~~ Any:D; # OUTPUT: «False␤»
say Foo ~~ Any:U; # OUTPUT: «True␤»
say Foo ~~ Any:_; # OUTPUT: «True␤»
# Checking an instance of a class
my $f = Foo.new;
say $f ~~ Any:D; # OUTPUT: «True␤»
say $f ~~ Any:U; # OUTPUT: «False␤»
Expand Down Expand Up @@ -399,7 +400,7 @@ object instance is always definite. Whether an object is a type
object/indefinite or an object instance/definite can be verified using the
L<DEFINITE|/language/mop#DEFINITE> (meta)method.
I<Definiteness> should be distinghuished from I<definedness>, which is concerned
I<Definiteness> should be distinguished from I<definedness>, which is concerned
with the difference between defined and undefined objects. Whether an object is
defined or undefined can be verified using the C<defined>-method, which is
implemented in class L<Mu|/type/Mu>. By default a type object is considered
Expand Down

0 comments on commit f759c7d

Please sign in to comment.