Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Corrections and prefixed method, refs #2683
  • Loading branch information
JJ committed Mar 21, 2019
1 parent a948e06 commit ab74b86
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions doc/Type/Code.pod6
Expand Up @@ -9,7 +9,7 @@
C<Code> is the ultimate base class of all code objects in Perl 6. It
exposes functionality that all code objects have. While thunks are
directly of type C<Code>, most code objects (such as those resulting
from blocks, subroutines or methods) will be of some subclass of C<Code>.
from blocks, subroutines or methods) will belong to some subclass of C<Code>.
=head1 Methods
Expand Down Expand Up @@ -55,7 +55,8 @@ corresponding parameters.
say &slow.assuming(10000000).&bench; # OUTPUT: «(10000000 7.5508834)␤»
For a sub with arity greater than one, you can use C<Whatever> C<*> for all of the positional parameters that are not "assumed".
For a sub with arity greater than one, you can use C<Whatever> C<*> for all of
the positional parameters that are not "assumed".
sub first-and-last ( $first, $last ) {
say "Name is $first $last";
Expand All @@ -67,13 +68,15 @@ For a sub with arity greater than one, you can use C<Whatever> C<*> for all of t
You can handle any combination of assumed and not assumed positional parameters:
sub longer-names ( $first, $middle, $last, $suffix ) {
say "Name is $first $middle $last $suffix";
}
=begin code
sub longer-names ( $first, $middle, $last, $suffix ) {
say "Name is $first $middle $last $suffix";
}
my &surname-public = &longer-names.assuming( *, *, 'Public', * );
my &surname-public = &longer-names.assuming( *, *, 'Public', * );
&surname-public.( 'Joe', 'Q.', 'Jr.'); # OUTPUT: «Name is Joe Q. Public Jr.␤»
&surname-public.( 'Joe', 'Q.', 'Jr.'); # OUTPUT: «Name is Joe Q. Public Jr.␤»
=end code
Named parameters can be assumed as well:
Expand Down Expand Up @@ -111,7 +114,7 @@ C<count> will return C<Inf>. Named parameters do not contribute.
say &args.count; # OUTPUT: «2␤»
say &slurpy.count; # OUTPUT: «Inf␤»
=head2 of
=head2 method of
Defined as:
Expand Down Expand Up @@ -148,11 +151,15 @@ Defined as:
multi method Str(Code:D: --> Str:D)
Will produce a warning. Use C<.perl> or C<.gist> instead.
Will output the method name, but also produce a warning. Use C<.perl> or
C<.gist> instead.
sub marine() { }
say ~&marine; # OUTPUT: «marine␤»
say &marine.Str; # OUTPUT: «marine␤»
say ~&marine;
# OUTPUT: «Sub object coerced to string (please use .gist or .perl to do that)␤marine␤»
say &marine.Str;
# OUTPUT: «Sub object coerced to string (please use .gist or .perl to do that)␤marine␤»
say &marine.perl; # OUTPUT: «sub marine { #`(Sub|94280758332168) ... }␤»
=head2 method file
Expand Down

0 comments on commit ab74b86

Please sign in to comment.