Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
several corrections by Philipp Marek
  • Loading branch information
moritz committed Mar 11, 2012
1 parent c6ccbe3 commit 0e0ac08
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
20 changes: 11 additions & 9 deletions src/classes-and-objects.pod
Expand Up @@ -407,8 +407,8 @@ defined in the Employee class as though they were from the Programmer class.
=head2 Overriding Inherited Methods

Of course, classes can override methods and attributes defined on ancestoral
classes by defining their own. The example below demonstrates the Baker class
overriding the Cook's cook method.
classes by defining their own. The example below demonstrates the C<Baker> class
overriding the C<Cook>'s C<cook> method.

=begin programlisting

Expand Down Expand Up @@ -447,8 +447,8 @@ overriding the Cook's cook method.

=end programlisting

Because the dispatcher will see the cook method on Baker before it moves up to
the parent class the Baker's cook method will be called.
Because the dispatcher will see the C<cook> method on C<Baker> before it moves up to
the parent class the C<Baker>'s C<cook> method will be called.

=head2 Multiple Inheritance

Expand Down Expand Up @@ -483,11 +483,12 @@ significant improvement over Perl 5's approach to handling multiple inheritance.
Now all the methods made available by both the Programmer class and the Cook
class are available from the GeekCook class.

While multiple inheritance is a useful concept to know and on occasion use, it
While multiple inheritance is a useful concept to know and on occasion of use, it
is important to understand that there are more useful OOP concepts. When
reaching for multiple inheritance it is good practice to consider whether the
design wouldn't be better realized by using roles. For more information on roles
check out the Roles chapter.
design wouldn't be better realized by using roles, which are generally safer
because they force the class author to explicitly resolve conflicting method
names. For more information on roles see A<sec:roles>.

=head1 Introspection

Expand All @@ -514,7 +515,8 @@ The output can look like this:

It's an employee
Programmer()
Programmer.new(known_languages => ["Perl", "Python", "Pascal"], favorite_editor => "gvim", salary => "too small")
Programmer.new(known_languages => ["Perl", "Python", "Pascal"],
favorite_editor => "gvim", salary => "too small")
code_to_solve, known_languages, favorite_editor

=end screen
Expand All @@ -529,7 +531,7 @@ which tells the exact type of C<$o>: in this case C<Programmer>.

C<$o.perl> returns a string that can be executed as Perl code, and reproduces
the original object C<$o>. While this does not work perfectly in all
casesN<for example closures cannot easily be reproduced this way; if you don't
casesN<For example closures cannot easily be reproduced this way; if you don't
know what a closure is don't worry. Also current implementations have problems
with dumping cyclic data structures this way, but they are expected to be
handlded correctly by C<.perl> at some point.>, it
Expand Down
2 changes: 1 addition & 1 deletion src/grammars.pod
Expand Up @@ -327,7 +327,7 @@ X<AST>

An abstract syntax tree, or AST, is a data structure which represents the
parsed version of the text. Your grammar describes the structure of the AST:
its root element is the C<TOP> node, which contain children of the allowed
its root element is the C<TOP> node, which contains children of the allowed
types and so on.

=end sidebar
Expand Down
12 changes: 6 additions & 6 deletions src/multi-dispatch.pod
Expand Up @@ -7,9 +7,9 @@ X<multis>
Perl usually decides which function to call based on the name of the function
or the contents of a function reference. This is simple to understand. Perl
can also examine the contents of the arguments provided to decide which of
several variants of a function--variants each with the same name--to call. In
several variants of a function--each with the same name--to call. In
this case, the amount and types of the function's arguments help to distinguish
between multiple variants of a function. This is I<multidispatch>, and the
between the variants of a function. This is called I<multidispatch>, and the
functions to which Perl can dispatch in this case are I<multis>.

X<JSON>
Expand Down Expand Up @@ -90,7 +90,7 @@ string C<'true'> or C<'false'>.

The C<Str> candidate does more work: it wraps its parameter in quotes and
escapes literal characters that the JSON spec does not allow in strings--a
tab character becomes C<\t>, a newline C<\n>, and so on.
tab character becomes C<"\t">, a newline C<"\n">, and so on.

The C<to-json(Array $d)> candidate converts all elements of the array to JSON
with recursive calls to C<to-json>, joins them with commas, and surrounds them
Expand Down Expand Up @@ -173,10 +173,10 @@ best candidate match, so the where block never executes and the first
C<$counter> output is always C<0>.

The output after the second call is at least C<1>. The compiler has to execute
the where-block at least once to check if the third candidate is the best
the C<where>-block at least once to check if the third candidate is the best
match, but the specification does not require the I<minimal> possible number of
runs. This is illustrated in the second C<$counter> output. The specific
implementation used to run this test actually executes the where-block twice.
implementation used to run this test actually executes the C<where>-block twice.
Keep in mind that the number of times the subtype checks blocks execute is
specific to any particular implementation of Perl 6.

Expand Down Expand Up @@ -347,7 +347,7 @@ languages). It binds the nominal type of the first argument to C<T>, which can
then act as a type constraint. If you pass a C<Rock> as the first argument,
C<T> acts as an alias for C<Rock> inside the rest of the signature and the body
of the routine. The signature C<(::T $, T $)> will bind only two objects of the
same type, or where the second is of a subtype of the first.
same type, or where the second is a subtype of the first.

In this game, that fourth candidate matches only for two objects of the same
type. The routine returns C<0> to indicate a draw.
Expand Down
28 changes: 15 additions & 13 deletions src/regexes.pod
Expand Up @@ -14,13 +14,13 @@ these patterns to actual text to look for matches. Most modern regular
expression facilities are more powerful than traditional regular expressions
due to the influence of languages such as Perl, but the short-hand term
C<regex> has stuck and continues to mean "regular expression-like pattern
matching". In Perl 6, though the specific syntax used to describe the
matching". In Perl 6, although the specific syntax used to describe the
patterns is different from PCREN<B<P>erl B<C>ompatible B<R>egular
B<E>xpressions> and POSIXN<B<P>ortable B<O>perating B<S>ystem B<I>nterface for
UniB<x>. See IEEE standard 1003.1-2001>, we continue to call them C<regex>.

A common writing error is to duplicate a word by accident. It is hard to
catch such errors by rereading your own text, but Perl can do it for you
catch such errors by re-reading your own text, but Perl can do it for you
using C<regex>:

=begin programlisting
Expand Down Expand Up @@ -109,9 +109,10 @@ X<match object>

The dot matched an C<l>, C<r>, and C<n>, but it will also match a space in the
sentence I<< the spectroscoB<pe l>acks resolution >>--regexes ignore word
boundaries by default. The special variable C<$/> stores (among other things)
only the part of the string that matched the regular expression. C<$/> holds
these so-called I<match object>s.
boundaries by default.

The special variable C<$/> stores the I<match object>, which allows you
inspect the matched text.

X<regex, \w>

Expand All @@ -123,7 +124,7 @@ regex for that is C<m/pe \w l/>. The C<\w> control sequence stands for a
uses C<\w> to build the definition of a "word".

Several other common control sequences each match a single character; you can
find a list of those in L<regex_backslash>.
find a list of those in A<regex_backslash>.

=begin table Backslash sequences and their meaning

Expand Down Expand Up @@ -348,7 +349,7 @@ non-greedyN<The non-greedy general quantifier is C<$thing **? $count>, so the
question mark goes directly after the second asterisk.>

For example, you can parse HTML very badlyN<Using a proper stateful parser is
always more accurate.>with the code:
always more accurate.> with the code:

=begin programlisting

Expand Down Expand Up @@ -379,8 +380,8 @@ items with square brackets:

X<regex, alternation>

Separate I<alternations>--parts of a regex of which I<any> can match--
with vertical bars. One vertical bar between multiple parts of a regex
Separate I<alternations>--parts of a regex of which I<any> can match--with
vertical bars. One vertical bar between multiple parts of a regex
means that the alternatives are tried in parallel and the longest
matching alternative wins. Two bars make the regex engine try each
alternative in order and the first matching alternative wins.
Expand Down Expand Up @@ -580,7 +581,8 @@ contractions such as C<doesn't> or C<isn't>:
X<regex, backreference>

This code introduces a regex named C<word>, which matches at least one word
character, optionally followed by a single quote. Another regex called C<dup>
character, optionally followed by a single quote and some more word characters.
Another regex called C<dup>
(short for I<duplicate>) contains a word boundary anchor.

Within a regex, the syntax C<< <&word> >> locates the regex C<word> within the
Expand Down Expand Up @@ -735,8 +737,8 @@ X<subst>
X<substitutions>

Regexes are also good for data manipulation. The C<subst> method matches a
regex against a string. With C<subst> matches, it substitutes the matched
portion of the string its the second operand:
regex against a string. When C<subst> matches, it substitutes the matched
portion of the string with its the second operand:

=begin programlisting

Expand All @@ -759,7 +761,7 @@ X<operators, m//>
Note the use of C<rx/ ... /> rather than C<m/ ... /> to construct the regex.
The former constructs a regex object. The latter constructs the regex object
I<and> immediately matches it against the topic variable C<$_>. Using C<m/
... /> in the call to C<subst> creates a match object and passes it as the
... /> in the call to C<subst> would create a match object and pass it as the
first argument, rather than the regex itself.

=head1 Other Regex Features
Expand Down

0 comments on commit 0e0ac08

Please sign in to comment.