Skip to content

Commit 74fd84f

Browse files
committed
Merge branch 'master' of github.com:nxadm/doc
2 parents 2de6cf2 + ce1302c commit 74fd84f

36 files changed

+817
-350
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
addons:
2+
apt:
3+
packages:
4+
- graphviz
15
branches:
26
except:
37
- gh-pages
@@ -8,3 +12,6 @@ perl6:
812
install:
913
- rakudobrew build-panda
1014
- panda installdeps .
15+
- panda install Pod::To::HTML
16+
17+
script: make test && make html

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# p6doc -- an attempt to write something like 'perldoc' for Perl 6
22

3+
[![Build Status](https://travis-ci.org/perl6/doc.svg?branch=master)](https://travis-ci.org/perl6/doc) [![artistic](https://img.shields.io/badge/license-Artistic%202.0-blue.svg?style=flat)](https://opensource.org/licenses/Artistic-2.0)
4+
35
An HTML version of this documentation can be found at http://doc.perl6.org/.
46

57
(If you are browsing this repository via github, it will not display most

bin/p6doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env perl6
2+
use MONKEY-SEE-NO-EVAL; # until we have a better serialisation
23

34
# die with printing a backtrace
45
my class X::P6doc is Exception {

bin/p6doc-index

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env perl6
22
use v6;
33
use File::Find;
4+
use MONKEY-SEE-NO-EVAL; # until we have a better serialisation
45

56
# XXX this script probably should be refactored into p6doc itself
67

doc/Language/5to6-nutshell.pod

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ variable holding a code object as an argument:
234234
&first_index($coderef, @values); # (disabling the prototype that parses a
235235
# literal block as the first argument)
236236
# Perl 6:
237-
first-index { $_ > 5 }, @values;
238-
first-index $coderef, @values;
237+
first { $_ > 5 }, @values, :k; # the :k makes first return an index
238+
first $coderef, @values, :k;
239239
=end item
240240
241241
=begin item
@@ -618,6 +618,10 @@ translation.
618618
In scalar context, C<..> and C<...> were the little-known Flipflop
619619
operators. They have been replaced by C<ff> and C<fff>.
620620
621+
=head3 String interpolation
622+
623+
In Perl 5, C<"${foo}s"> deliminates a variable name from regular text next to it.
624+
In Perl 6, simply extend the curly braces to include the sigil too: C<"{$foo}s">
621625
622626
=head2 Compound Statements
623627
@@ -900,7 +904,8 @@ was written first.
900904
The simplest way to deal with this is just to change any C<|> in your
901905
Perl 5 regex to a C<||>.
902906
903-
TODO more rules. Use C<translate_regex.pl> from Blue Tiger in the meantime.
907+
TODO more rules. Use L<< C<translate_regex.pl> from Blue
908+
Tiger|https://github.com/Util/Blue_Tiger/ >> in the meantime.
904909
905910
=head2 Pragmas
906911

doc/Language/5to6-perlfunc.pod

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,11 @@ used as a method: C<@new = @old.map: { $_ * 2 }>
797797
798798
=item mkdir FILENAME
799799
800+
Works as in Perl 5.
801+
800802
=item mkdir
801803
802-
Works as in Perl 5.
804+
The zero argument (implicit C<$_>) version is not permitted in Perl 6.
803805
804806
=head2 msg*
805807
@@ -1344,7 +1346,6 @@ Available in Perl 6. Can also be used as a method. C<< splice(@foo, 2,3,
13441346
13451347
=item split /PATTERN/
13461348
1347-
=item split
13481349
13491350
Works mostly as in Perl 5. There are some exceptions, though. To get the
13501351
special behavior of using the empty string, you must actually use the
@@ -1358,6 +1359,11 @@ they are in Perl 5. For that behavior, see C<comb>. Details on C<split>
13581359
are at L<http://doc.perl6.org/routine/split>. Unsurprisingly, C<split>
13591360
also now works as a method: C<"a;b;c".split(';')>
13601361
1362+
=item split
1363+
1364+
The zero argument version must now be called with an explicit empty string, as
1365+
described above.
1366+
13611367
=head2 sprintf
13621368
13631369
=item sprintf FORMAT, LIST
@@ -1624,9 +1630,12 @@ callframe.annotations<file line>;>
16241630
16251631
=item unlink LIST
16261632
1633+
Still available. Usable as a method: C<"filename".IO.unlink>
1634+
16271635
=item unlink
16281636
1629-
Still available. Usable as a method: C<"filename".IO.unlink>
1637+
The zero argument (implicit C<$_>) version of unlink is not available in Perl
1638+
6.
16301639
16311640
=head2 unpack
16321641

doc/Language/classtut.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ handle default values too:
360360
has @!dependencies;
361361
has Bool ($.done, $.ready);
362362
submethod BUILD(
363-
:@!callback,
363+
:&!callback,
364364
:@!dependencies,
365365
:$!done = False,
366366
:$!ready = not @!dependencies

doc/Language/concurrency.pod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
In common with most modern programming languages, Perl 6 is designed to
88
L<support concurrency|http://en.wikipedia.org/wiki/Concurrent_computing>
99
(allowing more than one thing to happen at the same time) and
10-
asynchronous programming (sometime called event driven or reactive
10+
asynchronous programming (sometimes called event driven or reactive
1111
programming - that is an event or change in some part of a program
1212
may lead to an event or change in some other part of the program
1313
asynchronously to the program flow).
@@ -63,14 +63,14 @@ chaining:
6363
$promise1.keep("First Result");
6464
say $promise2.result; # First Result \n Second Result
6565
66-
Here the L<then|/type/Promise#method_then> schedules code to be
66+
Here the L<then|/type/Promise#method_then> method schedules code to be
6767
executed when the first L<Promise> is kept or broken, itself returning
6868
a new L<Promise> which will be kept with the result of the code when
6969
it is executed (or broken if the code fails.) C<keep> changes the
7070
status of the promise to C<Kept> setting the result to the positional
7171
argument. C<result> blocks the current thread of execution until the
7272
promise is kept or broken, if it was kept then it will return the
73-
result (that is the value passed to C<keep>, ) or it will throw an
73+
result (that is the value passed to C<keep>, ) otherwise it will throw an
7474
exception based on the value passed to C<break>. The latter behaviour
7575
is illustrated with:
7676
@@ -177,14 +177,14 @@ original promises is kept or broken when any of them is broken:
177177
Unlike C<await> however the results of the original kept promises are not
178178
available without referring to the original, so these are more useful
179179
when the completion or otherwise of the tasks is more important to the
180-
consumer than the actual results, or the results have been collected by
181-
other means.
180+
consumer than the actual results, or when the results have been collected
181+
by other means.
182182
183183
If you are creating a promise that you intend to keep or break yourself
184184
then you probably don't want any code that might receive the promise to
185185
inadvertently (or otherwise,) keep or break the promise before you do.
186186
For this purpose there is the L<method vow|/type/Promise#method_vow>, which
187-
returns a L<Vow> object which becomes the only mechanism by the promise
187+
returns a L<Vow> object which becomes the only mechanism by which the promise
188188
can be kept or broken. If an attempt to keep or break the Promise is made
189189
directly then the exception L<X::Promise::Vowed> will be thrown, as long
190190
as the vow object is kept private, the status of the promise is safe:
@@ -292,8 +292,8 @@ This could also be written using the C<react> keyword:
292292
}
293293
}
294294
295-
Here the C<whenever> creates a tap on the L<Supply> from the provided block,
296-
the C<react> being exited when C<done()> is called in one of the taps.
295+
Here the C<whenever> keyword creates a tap on the L<Supply> from the provided
296+
block. The C<react> block is exited when C<done()> is called in one of the taps.
297297
298298
A second argument can be supplied to C<interval> which specifies a delay
299299
in seconds before the first event is fired. Each tap of a supply created
@@ -492,8 +492,8 @@ an external program asynchronously:
492492
# Output: foo bar
493493
# Done.
494494
495-
The path to the command and any arguments are supplied to
496-
the constructor but the program will not be started until
495+
The path to the command as well as any arguments to the command are
496+
supplied to the constructor. The command will not be executed until
497497
L<start|/type/Proc::Async#method_start> is called, which will return
498498
a L<Promise> that will be kept when the program exits. The standard
499499
output and standard error of the program are available as L<Supply>
@@ -566,8 +566,8 @@ to be useful directly in user code.
566566
567567
=head2 Schedulers
568568
569-
The next level of the concurrency API is that supplied by classes that
570-
provide the interface defined by the role L<Scheduler>. The intent
569+
The next level of the concurrency API is supplied by classes that
570+
implement the interface defined by the role L<Scheduler>. The intent
571571
of the scheduler interface is to provide a mechanism to determine which
572572
resources to use to run a particular task and when to run it. The majority
573573
of the higher level concurrency APIs are built upon a scheduler and it

doc/Language/control.pod

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,57 @@
44
55
=SUBTITLE Statements used to control the flow of execution
66
7+
=head2 X<statements|control flow>
8+
9+
Perl 6 programs consists of one or more statements. Simple statements
10+
are separated by semicolons. The following program will say "Hello"
11+
and then say "World" on the next line.
12+
13+
say "Hello";
14+
say "World";
15+
16+
In most places where spaces appear in a statement, and before the
17+
semicolon, it may be split up over many lines. Also, multiple statements
18+
may appear on the same line. It would be awkward, but the above could
19+
also be written as:
20+
21+
say
22+
"Hello"; say "World";
23+
724
=head2 X<blocks|control flow>
825
9-
Like many languages, Perl6 uses C<blocks> delimited by C<{> and C<}>
10-
to compartmentalize code. When a block stands alone as a statement,
11-
it will be entered immediately after the statement before it finishes,
12-
and the statements inside it will be executed. Otherwise, a block
13-
simply creates a closure, which may be executed at a later time:
26+
Like many languages, Perl6 uses C<blocks> enclosed by C<{> and C<}> to turn
27+
multiple statements into a single statement. It is ok to skip the semicolon
28+
between the last statement in a block and the closing C<}>.
29+
30+
{ say "Hello"; say "World" }
31+
32+
When a block stands alone as a statement, it will be entered immediately
33+
after the previous statement finishes, and the statements inside it will be
34+
executed.
35+
36+
say 1; # says "1"
37+
{ say 2; say 3 }; # says "2" then says "3"
38+
say 4; # says "4"
39+
40+
Unless it stands alone as a statement, a block simply creates a closure. The
41+
statements inside are not executed immediately. Closures are another topic
42+
and how they are used is explained
43+
L<elsewhere|language/functions#Blocks and Lambdas>. For now it is just
44+
important to understand when blocks run and when they do not:
1445
1546
say "We get here"; { say "then here." }; { say "not here"; 0; } or die;
1647
17-
In the above example, after running the first statement, the first
18-
block stands alone as a second statement, so we run the statement inside
19-
it. The second block does not stand alone as a statement, so it instantiates
20-
an object of type C<Block>, but does not run it. Since any object instance
21-
is true, the code does not die, even though that block would evaluate to 0,
22-
were it to be executed.
48+
In the above example, after running the first statement, the first block stands
49+
alone as a second statement, so we run the statement inside it. The second
50+
block does not stand alone as a statement, so instead, it makes an object of
51+
type C<Block> but does not run it. Object instances are usually considered to
52+
be true, so the code does not die, even though that block would evaluate to 0,
53+
were it to be executed. The example does not say what to do with the C<Block>
54+
object, so it just gets thrown away.
2355
24-
Most of the flow control constructs covered below are just ways to
25-
tell perl6 when, how, and how many times, to enter blocks like that
26-
second block.
56+
Most of the flow control constructs covered below are just ways to tell perl6
57+
when, how, and how many times, to enter blocks like that second block.
2758
2859
Before we go into those, an important side-note on syntax: If there is
2960
nothing (or nothing but comments) on a line after a closing curly brace where
@@ -116,19 +147,13 @@ run the block, or it will return the value which the block produces:
116147
my $c = 0; say (1, (if 1 { $c += 42; 2; }), 3, $c); # says "1 2 3 42"
117148
my $d = 0; say (1, (if 0 { $d += 42; 2; }), 3, $d); # says "1 3 0"
118149
119-
Implementation note: Currently, Rakudo will say "1 Nil 3 0" for the last
120-
example because it is not caught up to this part of the design yet.
121-
122150
For the statement modifier it is the same, except you have the value
123151
of the statement instead of a block:
124152
125153
say (1, (42 if True) , 2); # says "1 42 2"
126154
say (1, (42 if False), 2); # says "1 2"
127155
say (1, 42 if False , 2); # says "1 42" because "if False, 2" is true
128156
129-
Implementation note: Currently, Rakudo will say "1 Nil 2" for the second
130-
example because it is not caught up to this part of the design yet.
131-
132157
The C<if> does not change the topic (C<$_>) by default. In order to access
133158
the value which the conditional expression produced, you have to ask
134159
for it more strongly:
@@ -200,9 +225,6 @@ or the value produced by the block that did run:
200225
(if 0 { $d += 42; "two"; } elsif False { $d += 43; 2; }),
201226
3, $d); # says "1 3 0"
202227
203-
Implementation note: Currently, Rakudo will say "1 Nil 3 0" for the last
204-
example because it is not caught up to this part of the design yet.
205-
206228
It's possible to obtain the value of the previous expression inside an
207229
C<else>, which could be from C<if> or the last C<elsif> if any are
208230
present:
@@ -234,9 +256,6 @@ two differences C<unless> works the same as L<if>:
234256
my $c = 0; say (1, (unless 0 { $c += 42; 2; }), 3, $c); #-> says "1 2 3 42"
235257
my $c = 0; say (1, (unless 1 { $c += 42; 2; }), 3, $c); #-> says "1 3 0"
236258
237-
Implementation note: Currently, Rakudo will say "1 Nil 3 0" for the last
238-
example because it is not caught up to this part of the design yet.
239-
240259
=head3 X<with, orwith, without|control flow,with orwith without>
241260
242261
The C<with> statement is like C<if> but tests for definedness rather than
@@ -394,7 +413,8 @@ as though the rest of the statements in the block are skipped.
394413
}
395414
# The above block evaluates to 43
396415
397-
A C<when> statement will also do this.
416+
A C<when> statement will also do this (but a C<when> statement modifier
417+
will I<not>.)
398418
399419
In addition, C<when> statements C<smartmatch> the topic (C<$_>) against
400420
a supplied expression such that it is possible to check against values,
@@ -417,6 +437,20 @@ C<when> statements. The following code says C<"Int"> not C<42>.
417437
}
418438
#-> Int
419439
440+
When a C<when> statement or C<default> statement causes the outer
441+
block to return, nesting C<when> or C<default> blocks do not count
442+
as the outer block, so you can nest these statements and still
443+
be in the same "switch" just so long as you do not open a new block:
444+
445+
given 42 {
446+
when Int {
447+
when 42 { say 42 }
448+
say "Int"
449+
}
450+
default { say "huh?" }
451+
}
452+
#-> 42
453+
420454
=head3 X<proceed and succeed|control flow,proceed succeed>
421455
422456
Both C<proceed> and C<succeed> are meant to be used only from inside C<when>
@@ -479,6 +513,22 @@ specify a final value for the block.
479513
}
480514
#-> Int
481515
516+
If you are not inside a when or default block, it is an error to try
517+
to use C<proceed> or C<succeed>. Also remember, the C<when> statement
518+
modifier form does not cause any blocks to be left, and any C<succeed>
519+
or C<proceed> in such a statement applies to the surrounding clause,
520+
if there is one:
521+
522+
given 42 {
523+
{ say "This says" } when Int;
524+
"This says too".say;
525+
when * > 41 {
526+
{ "And this says".say; proceed } when * > 41;
527+
"This never says".say;
528+
}
529+
"This also says".say;
530+
}
531+
482532
=head2 X<loop|control flow>
483533
484534
The C<loop> statement is the C-style C<for> loop in disguise:

0 commit comments

Comments
 (0)