Skip to content

Commit

Permalink
More clarifications, reindentations and reflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Feb 4, 2019
1 parent 9787750 commit ab39e38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions doc/Type/Capture.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Defined as:
Returns the number of positional elements in the Capture.
my Capture $c = \(2, 3, 5, apples => (red => 2));
say $c.elems; # OUTPUT: «3␤»
say $c.elems; # OUTPUT: «3␤»
=head2 method keys
Expand All @@ -114,7 +114,7 @@ named keys. For positional arguments the keys are the respective arguments
ordinal position starting from zero.
my $capture = \(2, 3, 5, apples => (red => 2));
say $capture.keys; # OUTPUT: «(0 1 2 apples)␤»
say $capture.keys; # OUTPUT: «(0 1 2 apples)␤»
=head2 method values
Expand All @@ -126,7 +126,7 @@ Returns a L<Seq|/type/Seq> containing all positional values followed by all
named argument values.
my $capture = \(2, 3, 5, apples => (red => 2));
say $capture.values; # OUTPUT: «(2 3 5 red => 2)␤»
say $capture.values; # OUTPUT: «(2 3 5 red => 2)␤»
=head2 method kv
Expand Down Expand Up @@ -204,4 +204,4 @@ Returns the number of positional elements in the Capture.
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
40 changes: 20 additions & 20 deletions doc/Type/Mu.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ say $p.perl;
# OUTPUT: «Point-with-ID.new(ID => "*1-2", x => 1, y => 2)␤»
=end code
In this code, C<bless> called within C<Point.new> is eventually calling C<BUILD>
with the same parameters. We have to create a convoluted way of using the
C<$.ID> attribute using the meta-object protocol so that we can instantiate it
and thus serve that C<new> constructor, which can be called on C<Point-with-ID>
since it is a subclass.
In this code, C<bless>, called within C<Point.new>, is eventually calling
C<BUILD> with the same parameters. We have to create a convoluted way of using
the C<$.ID> attribute using the meta-object protocol so that we can instantiate
it and thus serve that C<new> constructor, which can be called on
C<Point-with-ID> since it is a subclass.
We might have to use something similar if we want to instantiate superclasses.
C<bless> will help us with that, since it is calling across all the hierarchy:
Expand All @@ -373,20 +373,20 @@ class Str-with-ID is Str {
say Str-with-ID.new("1.1,2e2").ID; # OUTPUT: «0␤»
my $ided-str = Str-with-ID.new("3,4");
say "$ided-str, {$ided-str.^name}, {$ided-str.ID}"; # OUTPUT: «3,4, Str-with-ID, 1␤»
say "$ided-str, {$ided-str.^name}, {$ided-str.ID}";
# OUTPUT: «3,4, Str-with-ID, 1␤»
=end code
We are *enriching* C<Str> with an auto-incrementing ID. We create a C<new> since
we want to initialize it with a string and, besides, we need to instantiate the
superclass. We do so using C<bless> from within C<new>. C<bless> is going to
call C<Str.BUILD>. It will *capture* the value it's
looking for, the pair C<value => $str> and initialize itself. But we have to
initialize also the properties of the subclass, which is why within C<BUILD> we
use the previously explained method to initialize C<$.ID> with the value that is
in the C<%args> variable. As shown in the output, the objects will be correctly
initialized with its ID, and will correctly behave as C<Str>, converting
themselves in just the string in the C<say> statement, and including the C<ID>
property as required.
We are I<enriching> C<Str> with an auto-incrementing ID. We create a C<new>
since we want to initialize it with a string and, besides, we need to
instantiate the superclass. We do so using C<bless> from within C<new>. C<bless>
is going to call C<Str.BUILD>. It will *capture* the value it's looking for, the
pair C<value => $str> and initialize itself. But we have to initialize also the
properties of the subclass, which is why within C<BUILD> we use the previously
explained method to initialize C<$.ID> with the value that is in the C<%args>
variable. As shown in the output, the objects will be correctly initialized with
its ID, and will correctly behave as C<Str>, converting themselves in just the
string in the C<say> statement, and including the C<ID> property as required.
For more details see
L<the documentation on object construction|/language/objects#Object_Construction>.
Expand Down Expand Up @@ -457,9 +457,9 @@ mechanism when no direct candidate is available to dispatch to.
multi method WHICH(--> ObjAt:D)
Returns an object of type L<ObjAt|/type/ObjAt> which uniquely identifies the object.
Value types override this method which makes sure that two equivalent objects
return the same return value from C<WHICH>.
Returns an object of type L<ObjAt|/type/ObjAt> which uniquely identifies the
object. Value types override this method which makes sure that two equivalent
objects return the same return value from C<WHICH>.
say 42.WHICH eq 42.WHICH; # OUTPUT: «True␤»
Expand Down
5 changes: 3 additions & 2 deletions doc/Type/Whatever.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
=TITLE class Whatever
=SUBTITLE Placeholder for an unspecified value/argument
=SUBTITLE Placeholder for the value of an unspecified argument
class Whatever { }
Expand Down Expand Up @@ -77,7 +77,8 @@ C<WhateverCode>s.
my $x = *;
$x + 2; # Not a closure, dies because it can't coerce $x to Numeric
CATCH { default { put .^name, ': ', .Str } };
# OUTPUT: «X::Multi::NoMatch: Cannot resolve caller Numeric(Whatever: ); none of these signatures match:␤
# OUTPUT: «X::Multi::NoMatch: Cannot resolve caller Numeric(Whatever: );
# none of these signatures match:␤
# (Mu:U \v: *%_)»
The use cases for stored C<Whatever>-stars involve those curry-exception
Expand Down

0 comments on commit ab39e38

Please sign in to comment.