Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Pod formatting, whitespace in Language/101-basics
  • Loading branch information
softmoth committed Jul 9, 2018
1 parent dd96e63 commit 979f7f9
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions doc/Language/101-basics.pod6
Expand Up @@ -31,7 +31,6 @@ of a match.
Here's one way to solve that problem in Perl 6:
=begin code
use v6;
my $file = open 'scores.txt';
Expand Down Expand Up @@ -60,20 +59,15 @@ Here's one way to solve that problem in Perl 6:
for @sorted -> $n {
say "$n has won %matches{$n} matches and %sets{$n} sets";
}
=end code
This produces the output:
=output
Ana has won 2 matches and 8 sets
Dave has won 2 matches and 6 sets
Charlie has won 1 matches and 4 sets
Beth has won 1 matches and 4 sets
=output
=head3 X<C<v6>>
Every Perl 6 program should begin with C<use v6;>. This line tells the compiler
Expand All @@ -86,9 +80,7 @@ A Perl 6 program consists of zero or more statements. A I<statement> ends with
a semicolon or a curly bracket at the end of a line:
=begin code
my $file = open 'scores.txt';
=end code
=head3 X<C<lexical>> and X<C<block>>
Expand Down Expand Up @@ -135,9 +127,7 @@ literal is a string which appears directly in the program. In this line, it's
the argument provided to C<open>.
=begin code
my @names = $file.get.words;
=end code
=head3 X<C<array>>, X<C<method>> and X<C<invocant>>
Expand All @@ -157,10 +147,8 @@ stored in the array C<@names>. The C<@> sigil marks the declared variable as
an C<Array>. Arrays store ordered lists.
=begin code
my %matches;
my %sets;
=end code
=head3 X<C<hash>>
Expand All @@ -178,11 +166,9 @@ player has won. C<%sets> stores the number of sets each player has won. Both
of these hashes are indexed by the player's name.
=begin code
for $file.lines -> $line {
...
}
=end code
=head3 X<C<for>> and X<C<block>>
Expand All @@ -197,9 +183,7 @@ During the first iteration, C<$line> will contain the string C<Ana Dave |
3:0>; during the second, C<Charlie Beth | 3:1>, and so on.
=begin code
my ($pairing, $result) = $line.split(' | ');
=end code
C<my> can declare multiple variables simultaneously. The right-hand side of the
Expand All @@ -219,10 +203,8 @@ and C<$result> C<3:0>.
The next two lines follow the same pattern:
=begin code
my ($p1, $p2) = $pairing.words;
my ($r1, $r2) = $result.split(':');
=end code
The first extracts and stores the names of the two players in the variables
Expand All @@ -246,19 +228,15 @@ cell C<'0'>
The program then counts the number of sets each player has won:
=begin code
%sets{$p1} += $r1;
%sets{$p2} += $r2;
=end code
The C<+=> assignment operator is a shortcut for:
=begin code
%sets{$p1} = %sets{$p1} + $r1;
%sets{$p2} = %sets{$p2} + $r2;
=end code
=head3 X<C<Any>> and X<C<+=>>
Expand All @@ -278,13 +256,11 @@ have run for the first time, C<%sets> contains C<< 'Ana' => 3, 'Dave' => 0 >>.
(The fat arrow C<< => >> separates key and value in a C<Pair>.)
=begin code
if $r1 > $r2 {
%matches{$p1}++;
} else {
%matches{$p2}++;
}
=end code
If C<$r1> is numerically larger than C<$r2>, C<%matches{$p1}> increments by one.
Expand All @@ -301,9 +277,7 @@ programming languages, you can use C<++> as a prefix. Then it returns the
incremented value; C<my $x = 1; say ++$x> prints C<2>.
=begin code
my @sorted = @names.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse;
=end code
=head3 X<C<variables, $_>>
Expand Down Expand Up @@ -346,11 +320,9 @@ opposite of the desired order. Therefore, the code calls the C<.reverse> method
on the result of the second sort, and stores the final list in C<@sorted>.
=begin code
for @sorted -> $n {
say "$n has won %matches{$n} matches and %sets{$n} sets";
}
=end code
=head3 X<C<say>>, X<C<print>> and X<C<put>>
Expand Down Expand Up @@ -378,11 +350,9 @@ not interpolate:
=head3 X<C<double-quoted strings>> and X<C<single-quoted strings>>
=begin code
my $names = 'things';
say 'Do not call me $names'; # Do not call me $names
say "Do not call me $names"; # Do not call me things
=end code
Double quoted strings in Perl 6 can interpolate variables with the C<$>
Expand All @@ -405,7 +375,6 @@ When you put words in between the < and > they are all assumed to be strings,
so you do not need to wrap them each in double quotes C<< "..." >>.
=begin code
say "Math: { 1 + 2 }"; # Math: 3
my @people = <Luke Matthew Mark>;
say "The synoptics are: {@people}"; # The synoptics are: Luke Matthew Mark
Expand All @@ -416,7 +385,6 @@ so you do not need to wrap them each in double quotes C<< "..." >>.
# Dave 6
# Ana 8
# Beth 4
=end code
Expand All @@ -429,7 +397,6 @@ the postcircumfix.
=head3 X<C<Zen slice>>
=begin code
my @flavours = <vanilla peach>;
say "we have @flavours"; # we have @flavours
Expand All @@ -443,7 +410,6 @@ the postcircumfix.
# chained method calls:
say "we have @flavours.sort.join(', ')";
# we have peach, vanilla
=end code
Expand All @@ -460,17 +426,13 @@ Hint: C<%hash.keys> returns a list of all keys stored in C<%hash>.
B<Answer:> Remove the line C<my @names = $file.get.words;>, and change:
=begin code
my @sorted = @names.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse;
=end code
... into:
=begin code
my @sorted = %sets.keys.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse;
=end code
B<2.> Instead of deleting the redundant C<@names> variable, you can also use it to warn if a
Expand All @@ -484,7 +446,6 @@ the file, check to see that C<$p1> and C<$p2> are in C<@valid-players>. Note tha
for membership operators you can also use C<(elem)> and C<!(elem)>.
=begin code
...
my @valid-players = $file.get.words;
...
Expand All @@ -500,7 +461,6 @@ for membership operators you can also use C<(elem)> and C<!(elem)>.
}
...
}
=end code
=end pod
Expand Down

0 comments on commit 979f7f9

Please sign in to comment.