Skip to content

Commit 82740f8

Browse files
committed
Typographical etc. corrections to objects.pod
1 parent f1699aa commit 82740f8

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

lib/Language/objects.pod

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Native types are used for low-level types (like C<uint64>). They do not
1414
have the same capabilities as objects, though if you call methods on them,
1515
they are I<boxed> into normal objects.
1616
17-
Everything that you can store in a variable is either a native value, or an
17+
Everything that you can store in a variable is either a native value or an
1818
object. That includes literals, types (type objects), code and containers.
1919
2020
=head1 Using Objects
@@ -36,7 +36,7 @@ my $formatted-text = "Fourscore and seven years ago...".L<indent>B<(8)>;
3636
3737
C<$formatted-text> now contains the above text, but indented 8 spaces.
3838
39-
Multiple arguments just require a comma between them:
39+
Multiple arguments simply require a comma between them:
4040
4141
=for code :allow<B L>
4242
my @words = "Abe", "Lincoln";
@@ -50,7 +50,7 @@ say @words.L<join>: '--';
5050
# Abe--Lincoln--said--Fourscore--and--seven--years--ago
5151
5252
Since you have to put a C<:> after the method if you want to pass arguments
53-
without parenthesis, a method call without a colon or parens is unambiguously
53+
without parentheses, a method call without a colon or parens is unambiguously
5454
a method call without an argument list:
5555
5656
$computation-result.say;
@@ -75,7 +75,7 @@ of the type hierarchy. In other words, all objects are derived from C<Mu>.
7575
7676
=head2 Type Objects
7777
78-
Types themselves are objects, and you can get the I<type object> simply
78+
Types themselves are objects and you can get the I<type object> simply
7979
by writing its name:
8080
8181
my $int-type-obj = Int;
@@ -149,7 +149,7 @@ are typically declared using the C<has> declarator and using the C<!> twigil.
149149
150150
While there is no such thing as a public (or even protected) attribute, there
151151
is a way to have accessor methods generated automatically: replace the C<!>
152-
twigil with the C<.> twigil (the C<.> should remind you of method call).
152+
twigil with the C<.> twigil (the C<.> should remind you of a method call).
153153
154154
class Journey {
155155
has $.origin;
@@ -169,7 +169,7 @@ the attribute, add the C<rw> trait:
169169
}
170170
171171
Now, after a C<Journey> object is created, its C<.origin>,
172-
C<.destination>, and C<.notes> will all be accessible from outside of the
172+
C<.destination>, and C<.notes> will all be accessible from outside the
173173
class, but only C<.notes> can be modified.
174174
175175
Since classes inherit a default constructor from C<Mu> and we have requested
@@ -196,7 +196,7 @@ accessor method.
196196
197197
=head2 Methods
198198
199-
Methods are declared with the C<method> keyword inside of a class body.
199+
Methods are declared with the C<method> keyword inside a class body.
200200
201201
=begin code :allow<B L>
202202
class Journey {
@@ -221,29 +221,29 @@ Methods are declared with the C<method> keyword inside of a class body.
221221
=end code
222222
223223
A method can have a signature, just like a subroutine. Attributes can be used
224-
in methods, and can always be used with the C<!> twigil, even if they are
224+
in methods and can always be used with the C<!> twigil, even if they are
225225
declared with the C<.> twigil. This is because really, the C<.> twigil declares
226-
an attribute with the C<!> twigil in its place, and then additionally generates
226+
an attribute with the C<!> twigil in its place and then additionally generates
227227
an accessor method.
228228
229229
There is a subtle but important difference between using, say, C<$!origin> and
230230
C<$.origin> in the method C<describe>. The first is always a simple lookup of
231231
the attribute. It is cheap, and you know that it is the attribute declared in
232-
this class. The latter is really a method call, and thus it may be overridden
232+
this class. The latter is really a method call and thus it may be overridden
233233
in a subclass. Only use C<$.origin> if you explicitly want to allow overriding.
234234
235235
=head2 self
236236
237-
Inside a method, the term C<self> is available, which is bound to invocant, i.e.
237+
Inside a method, the term C<self> is available, which is bound to the invocant, i.e.
238238
the object that the method was called on. C<self> can be used to call further
239-
methods on the invocant, for example. Within methods, something like
239+
methods on the invocant. Within methods, something like
240240
C<$.origin> is the same thing as C<self.origin>.
241241
242242
=head2 Private Methods
243243
244-
Methods for internal usage inside the class that cannot be called from
245-
anywhere else are introduced with an exclamation mark C<!> before the method
246-
name, and are called with the exclamation mark instead of the dot:
244+
Methods strictly for use inside the class and that are not to be called from
245+
anywhere else are declared with an exclamation mark C<!> before the method
246+
name. They are called with an exclamation mark instead of a dot:
247247
248248
method !do-something-private($x) {
249249
...
@@ -258,7 +258,7 @@ Private methods are not inherited to subclasses.
258258
259259
=head2 Submethods
260260
261-
A submethod is public method that is not inherited to subclasses. The name
261+
A submethod is a public method that is not inherited to subclasses. The name
262262
stems from the fact that they are semantically similar to subroutines.
263263
264264
Submethods are useful for object construction and destruction tasks, as well
@@ -275,12 +275,11 @@ Classes can have I<parent classes>.
275275
class Child B<L<is> Parent1 is Parent2> { }
276276
277277
If a method is called on the child class, and the child class does not
278-
provide that method, the parent classes' method of that name is invoked instead,
278+
provide that method, the method of that name in one of the parent classes is invoked instead,
279279
if it exists. The order in which parent classes are consulted is called the
280280
I<method resolution order> (MRO). Perl 6 uses the
281281
L<C3 method resolution order|https://en.wikipedia.org/wiki/C3_linearization>.
282-
You can ask a type for its MRO through a call to its metaclass:
283-
282+
You can ask a type for its MRO through a call to its meta class:
284283
285284
=for code :allow<B L>
286285
say ParcelB<.^L<mro>>; # Parcel() Cool() Any() Mu()
@@ -289,7 +288,7 @@ If a class does not specify a parent class, L<Any> is assumed by default. All
289288
classes directly or indirectly derive from L<Mu>, the root of the type
290289
hierarchy.
291290
292-
All calls to public method are "virtual" in the C++ sense, which means that
291+
All calls to public methods are "virtual" in the C++ sense, which means that
293292
the actual type of an object determines which method to call, not the declared
294293
type:
295294
@@ -317,7 +316,7 @@ This produces the output:
317316
318317
=head2 Object Construction
319318
320-
Objects are generally created through methods calls, either on the type object
319+
Objects are generally created through method calls, either on the type object
321320
or on another object of the same type.
322321
323322
Class L<Mu> provides a constructor method called L<new>, which takes named
@@ -350,10 +349,10 @@ This outputs:
350349
x: 5
351350
y: 10
352351
353-
Mu.new calls method L<bless> on its invocant, passing along all the named
354-
arguments. C<bless> creates the new object, and then calls method C<BUILDALL>
352+
C<Mu.new> calls method L<bless> on its invocant, passing all the named
353+
arguments. C<bless> creates the new object and then calls method C<BUILDALL>
355354
on it. C<BUILDALL> walks all subclasses in reverse method resolution order
356-
(i.e. from L<Mu> to most derived classes), and in each class checks for
355+
(i.e. from L<Mu> to most derived classes) and in each class checks for
357356
existence of a method named C<BUILD>. If it exists, it is called, again
358357
passing all named arguments from method C<new> to it. If not, the public
359358
attributes from this class are initialized from named arguments of the same
@@ -362,7 +361,7 @@ initialized the attribute, default values are applied (the C<2 * $!x> in the
362361
example above).
363362
364363
Due to the nature of the default behavior of C<BUILDALL> and custom C<BUILD>
365-
submethods, you named arguments to the constructor C<new> derived from C<Mu>
364+
submethods, named arguments to the constructor C<new> derived from C<Mu>
366365
can correspond directly to public attributes of any of the classes in the
367366
method resolution order, or to any named parameter to any C<BUILD> submethod.
368367
@@ -388,8 +387,8 @@ time. They can also be used for creating aliases for attribute initialization:
388387
=end code
389388
390389
Since passing arguments to a routine binds the arguments to the parameters,
391-
a separate binding step is unnecessary if the attribute is used as parameter.
392-
So the example above could also have been written as:
390+
a separate binding step is unnecessary if the attribute is used as a parameter.
391+
Hence the example above could also have been written as:
393392
394393
=for code :allow<B L>
395394
submethod BUILD(:encoding(:$B<!>enc), :$B<!>data) {
@@ -420,9 +419,9 @@ use C<CREATE> to fiddle around with low-level workings.
420419
421420
Roles are in some ways similar to classes, in that they are a collection of
422421
attributes and methods. They differ in that roles are also meant for
423-
describing only parts of an object's behavior, and in how roles are applied to
422+
describing only parts of an object's behavior and in how roles are applied to
424423
classes. Or to phrase it differently, classes are meant for managing
425-
instances, and roles are meant for managing behavior and code reuse.
424+
instances and roles are meant for managing behavior and code reuse.
426425
427426
=begin code :allow<B L>
428427
role Serializable {
@@ -482,8 +481,8 @@ and a class C<Automobile>, for things that you can drive.
482481
my $t = Taurus.new;
483482
$t.steer; # Castrates $t
484483
485-
With this set-up, your poor customers will find themselves unable to
486-
turn their Taurus, and you won't be able to make more of your product!
484+
With this setup, your poor customers will find themselves unable to
485+
turn their Taurus and you won't be able to make more of your product!
487486
In this case, it may have been better to use roles:
488487
489488
role Bull-Like {
@@ -508,7 +507,7 @@ This code will die with something like:
508507
Method 'steer' must be resolved by class Taurus because it exists in
509508
multiple roles (Steerable, Bull-Like)
510509
511-
This check will save you and your customers a lot of headaches, and you
510+
This check will save you and your customers a lot of headaches and you
512511
can simply define your class instead as:
513512
514513
class Taurus does Bull-Like does Steerable {
@@ -548,7 +547,7 @@ This allows you to create roles that act as abstract interfaces.
548547
=begin code :allow<B L>
549548
role AbstractSerializable {
550549
method serialize() { B<L<...>> } # literal ... here marks the
551-
# method as a stub
550+
# method as a stub
552551
}
553552
554553
# the following is a compile time error, for example
@@ -580,7 +579,7 @@ objects; those objects are called I<meta objects>. Meta objects are, like
580579
ordinary objects, instances of classes, in this case we call them I<meta
581580
classes>.
582581
583-
For each object or class, you can get the meta object by calling C<.HOW> on
582+
For each object or class you can get the meta object by calling C<.HOW> on
584583
it. Note that although this looks like a method call, it is actually
585584
special-cased in the compiler, so it is more like a macro.
586585
@@ -599,7 +598,7 @@ C<Perl6::Metamodel::ClassHOW>.
599598
600599
But of course the meta model does much more for you. For example it allows you
601600
to introspect objects and classes. The calling convention for methods on meta
602-
objects is to call the method on the meta object, and pass in the object of
601+
objects is to call the method on the meta object and pass in the object of
603602
interest as first argument to the object. So to get the name of the class of
604603
an object, you could write:
605604
@@ -621,7 +620,7 @@ To get rid of using the same object twice, there is a shortcut:
621620
say 1.HOW.name(1); # Int
622621
623622
See L<Metamodel::ClassHOW|/type/Metamodel::ClassHOW> for documentation of
624-
the meta class of C<class>, and also the L<general documentation on the meta
623+
the meta class of C<class> and also the L<general documentation on the meta
625624
object protocol|/language/mop>.
626625
627626
=end pod

0 commit comments

Comments
 (0)