Skip to content

Commit 979ad54

Browse files
authored
Merge pull request #1 from perl6/master
update
2 parents 78097fc + bc5ec07 commit 979ad54

33 files changed

+946
-327
lines changed

assets/sass/style.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,17 @@ table#TOC {
512512
}
513513
}
514514

515+
tr.toc-level-4 {
516+
td {
517+
padding-top: 2pt;
518+
font-size: 0.8em;
519+
}
520+
521+
td.toc-text {
522+
padding-left: 16px;
523+
}
524+
}
525+
515526
td.toc-number {
516527
display: none;
517528
}
@@ -612,4 +623,4 @@ a[href*="//"]:not([href*="perl6.org"])::after,
612623
position: relative;
613624
overflow: hidden;
614625
width: 100%;
615-
}
626+
}

doc/Language/5to6-nutshell.pod6

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
This page attempts to provide a fast-path to the changes in syntax and
88
semantics from Perl 5 to Perl 6. Whatever worked in Perl 5 and must be
99
written differently in Perl 6, should be listed here (whereas many
10-
I<new> Perl 6 features and idioms are not).
10+
I<new> Perl 6 features and idioms need not).
1111
1212
Hence this should not be mistaken for a beginner tutorial or a
1313
promotional overview of Perl 6; it is intended as a technical reference
@@ -284,12 +284,13 @@ first $coderef, @values, :k;
284284
=end item
285285
286286
=begin item
287-
C<&foo;> I<and> C<goto &foo;> I<for re-using the caller's argument list /
288-
replacing the caller in the call stack>. Perl 6 can use either L<C<callsame>|/language/functions#index-entry-dispatch_callsame> for re-dispatching or L<C<nextsame>|/language/functions#index-entry-dispatch_nextsame> and L<C<nextwith>|/language/functions#index-entry-dispatch_nextwith>, which have no exact equivalent in Perl 5.
289-
290-
=begin comment
291-
# TODO: Suggest .nextsame and .nextwith once they've been implemented in Rakudo.
292-
=end comment
287+
C<&foo;> I<and> C<goto &foo;> I<for re-using the caller's argument
288+
list / replacing the caller in the call stack>. Perl 6 can use either
289+
L<C<callsame>|/language/functions#index-entry-dispatch_callsame> for
290+
re-dispatching or
291+
L<C<nextsame>|/language/functions#index-entry-dispatch_nextsame> and
292+
L<C<nextwith>|/language/functions#index-entry-dispatch_nextwith>, which have no
293+
exact equivalent in Perl 5.
293294
294295
=for code :lang<perl5>
295296
sub foo { say "before"; &bar; say "after" } # Perl 5
@@ -320,8 +321,8 @@ foo(3); # /language/functions#index-entry-dispatch_callsame
320321
In Perl 5, the C<*> sigil referred to the GLOB structure that Perl uses to
321322
store non-lexical variables, filehandles, subs, and formats.
322323
323-
(This should not be confused with the Perl 5 built-in C<glob()> function,
324-
which reads filenames from a directory).
324+
N<This should not be confused with the Perl 5 built-in C<glob()> function,
325+
which reads filenames from a directory.>
325326
326327
You are most likely to encounter a GLOB in code written on a early Perl
327328
version that does not support lexical filehandles, when a filehandle needed
@@ -1126,6 +1127,43 @@ As with Perl 5, comments work as usual in regexes.
11261127
11271128
/ word #`(match lexical "word") /
11281129
1130+
=head1 BEGIN, UNITCHECK, CHECK, INIT and END
1131+
1132+
Except for C<UNITCHECK>, all of these special blocks exist in Perl 6 as well.
1133+
In Perl 6, these are called L<Phasers|/language/phasers>. But there are some
1134+
differences!
1135+
1136+
=head2 UNITCHECK becomes CHECK
1137+
1138+
There is currently B<no> direct equivalent of C<CHECK> blocks in Perl 6.
1139+
The C<CHECK> phaser in Perl 6 has the same semantics as the C<UNITCHECK>
1140+
block in Perl 5: it gets run whenever the compilation unit in which it
1141+
occurs, has finished parsing. This is considered a much saner semantic
1142+
than the current semantics of C<CHECK> blocks in Perl 5. But for
1143+
compatibility reasons, it was impossible to change the semantics of C<CHECK>
1144+
blocks in Perl 5, so a C<UNITCHECK> block was introduced in 5.10. So it
1145+
was decided that the Perl 6 C<CHECK> phaser would follow the saner Perl 5
1146+
C<UNITCHECK> semantics.
1147+
1148+
=head2 No block necessary
1149+
1150+
In Perl 5, these special blocks B<must> have curly braces, which implies a
1151+
separate scope. In Perl 6 this is not necessary, allowing these special
1152+
blocks to share their scope with the surrounding lexical scope.
1153+
1154+
=for code :lang<perl5>
1155+
my $foo; # Perl 5
1156+
BEGIN { $foo = 42 }
1157+
=for code
1158+
BEGIN my $foo = 42; # Perl 6
1159+
1160+
=head2 Changed semantics with regards to precompilation
1161+
1162+
If you put C<BEGIN> and C<CHECK> phasers in a module that is being
1163+
precompiled, then these phasers will B<only> be executed during precompilation
1164+
and B<not> when a precompiled module is being loaded. So when porting module
1165+
code from Perl 5, you may need to change C<BEGIN> and C<CHECK> blocks to
1166+
C<INIT> blocks to ensure that they're run when loading that module.
11291167
11301168
=head1 Pragmas
11311169
@@ -1218,7 +1256,8 @@ tau, pi, e, i; # built-in constants in Perl 6
12181256
12191257
=head3 C<encoding>
12201258
1221-
TODO Allows you to write your script in non-ascii or non-utf8.
1259+
Allows you to write your script in non-ascii or non-utf8. Perl 6 uses, for the
1260+
time being, only utf8 for its scripts.
12221261
12231262
=head3 C<integer>
12241263
@@ -1233,9 +1272,9 @@ say $foo * $bar; # uses native integer multiplication
12331272
12341273
=head3 C<lib>
12351274
1236-
Manipulate where modules are looked up at compile time. The underlying logic
1237-
is B<very> different from Perl 5, but in most cases, C<use lib> in Perl 6
1238-
works the same as in Perl 5.
1275+
Manipulate where modules are looked up at compile time. The underlying logic is
1276+
B<very> different from Perl 5, but in the case you are using a equivalent
1277+
syntax, C<use lib> in Perl 6 works the same as in Perl 5.
12391278
12401279
=head3 C<mro>
12411280
@@ -1332,7 +1371,8 @@ This is now the default behavior.
13321371
13331372
=item C<-S>, C<-T>.
13341373
1335-
This has been eliminated. Several ways to L<replicate "taint" mode are discussed in Reddit|https://www.reddit.com/r/perl6/comments/718z4o/taint_mode_for_perl_6/>.
1374+
This has been eliminated. Several ways to
1375+
L<replicate "taint" mode are discussed in Reddit|https://www.reddit.com/r/perl6/comments/718z4o/taint_mode_for_perl_6/>.
13361376
13371377
=head1 File-related operations
13381378
@@ -1370,7 +1410,7 @@ the C<lines> method on the result of C<slurp> instead:
13701410
13711411
my @lines = "test-file".IO.slurp.lines; # also auto-chomps
13721412
1373-
=head2 Trapping the standard output of executables.
1413+
=head2 Capturing the standard output of executables.
13741414
13751415
Whereas in Perl 5 you would do:
13761416
@@ -1489,7 +1529,7 @@ C<is export> role on the relevant subs and I<all> subs with this role are
14891529
then exported. Hence, the following module C<Bar> exports the subs C<foo>
14901530
and C<bar> but not C<baz>:
14911531
1492-
=begin code :skip-test
1532+
=begin code :skip-test<unit>
14931533
unit module Bar;
14941534
14951535
sub foo($a) is export { say "foo $a" }

doc/Language/5to6-perlfunc.pod6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ much as possible.
13371337
13381338
These survive the transition to Perl 6. Some notes:
13391339
1340-
=for code :skip-test
1340+
=for code :lang<perl5>
13411341
q/.../; # is still equivalent to using single quotes.
13421342
qq/.../; # is still equivalent to using double quotes.
13431343
qw/.../; # is more commonly rendered as C<< <...> >> in Perl 6.

doc/Language/classtut.pod6

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ possible to predict the moment when attribute initialization will be executed,
316316
because it can take place during compilation, runtime or both, especially when
317317
importing the class using the L<use|/syntax/use> keyword.
318318
319-
=begin code :skip-test
319+
=begin code :preamble<class Foo {}; sub some_complicated_subroutine {}>
320320
class HaveStaticAttr {
321321
my Foo $.foo = some_complicated_subroutine;
322322
}
@@ -493,7 +493,7 @@ After creating a class, you can create instances of the class. Declaring a
493493
custom constructor provides a simple way of declaring tasks along with their
494494
dependencies. To create a single task with no dependencies, write:
495495
496-
=for code :skip-test
496+
=for code :preamble<class Task {}>
497497
my $eat = Task.new({ say 'eating dinner. NOM!' });
498498
499499
An earlier section explained that declaring the class C<Task> installed a
@@ -505,7 +505,7 @@ modifying or accessing an existing object.
505505
506506
Unfortunately, dinner never magically happens. It has dependent tasks:
507507
508-
=begin code :skip-test
508+
=begin code :preamble<class Task {}>
509509
my $eat =
510510
Task.new({ say 'eating dinner. NOM!' },
511511
Task.new({ say 'making dinner' },
@@ -523,7 +523,7 @@ Notice how the custom constructor and sensible use of whitespace makes task depe
523523
Finally, the C<perform> method call recursively calls the C<perform> method
524524
on the various other dependencies in order, giving the output:
525525
526-
=begin code :skip-test
526+
=begin code :lang<output>
527527
making some money
528528
going to the store
529529
buying food
@@ -563,7 +563,7 @@ other means, such as attribute accessors.
563563
Now, any object of type Programmer can make use of the methods and accessors
564564
defined in the Employee class as though they were from the Programmer class.
565565
566-
=begin code :skip-test
566+
=begin code :preamble<class Programmer {}>
567567
my $programmer = Programmer.new(
568568
salary => 100_000,
569569
known_languages => <Perl5 Perl6 Erlang C++>,
@@ -580,7 +580,7 @@ Of course, classes can override methods and attributes defined by parent
580580
classes by defining their own. The example below demonstrates the C<Baker>
581581
class overriding the C<Cook>'s C<cook> method.
582582
583-
=begin code :skip-test
583+
=begin code :preamble<class Employee {}>
584584
class Cook is Employee {
585585
has @.utensils is rw;
586586
has @.cookbooks is rw;
@@ -636,7 +636,7 @@ classes when looking up a method to search for. Perl 6 uses the L<C3 algorithm
636636
multiple inheritance hierarchies, which is better than depth-first search
637637
for handling multiple inheritance.
638638
639-
=begin code :skip-test
639+
=begin code :preamble<class Programmer {}; class Cook {}>
640640
class GeekCook is Programmer is Cook {
641641
method new( *%params ) {
642642
push( %params<cookbooks>, "Cooking for Geeks" );
@@ -671,7 +671,7 @@ Classes to be inherited from can be listed in the class declaration body by
671671
prefixing the C<is> trait with C<also>. This also works for the role
672672
composition trait C<does>.
673673
674-
=begin code :skip-test
674+
=begin code :preamble<class Programmer {}; class Cook {}>
675675
class GeekCook {
676676
also is Programmer;
677677
also is Cook;
@@ -692,18 +692,17 @@ a controlling object) for some properties, such as its type.
692692
Given an object C<$o> and the class definitions from the previous sections,
693693
we can ask it a few questions:
694694
695-
=begin code :skip-test
695+
=begin code :preamble<my $o; class Employee {}; class GeekCook {}>
696696
if $o ~~ Employee { say "It's an employee" };
697697
if $o ~~ GeekCook { say "It's a geeky cook" };
698-
say $o.WHAT;
699698
say $o.perl;
700699
say $o.^methods(:local)».name.join(', ');
701700
say $o.^name;
702701
=end code
703702
704703
The output can look like this:
705704
706-
=begin code :skip-test
705+
=begin code :lang<output>
707706
It's an employee
708707
(Programmer)
709708
Programmer.new(known_languages => ["Perl", "Python", "Pascal"],
@@ -737,7 +736,7 @@ it is actually a method call on its I<meta class>, which is a class managing
737736
the properties of the C<Programmer> class – or any other class you are
738737
interested in. This meta class enables other ways of introspection too:
739738
740-
=for code :skip-test
739+
=for code :preamble<my $o>
741740
say $o.^attributes.join(', ');
742741
say $o.^parents.map({ $_.^name }).join(', ');
743742

0 commit comments

Comments
 (0)