From 814338d58c89774c3c9511d96756106f484a6d48 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 26 Feb 2020 05:33:34 -0600 Subject: [PATCH] change p6 to raku, chg .perl to .raku --- doc/Language/5to6-nutshell.pod6 | 4 +- doc/Language/classtut.pod6 | 22 +- doc/Language/classtut.raku | 472 +++++++++++++++++++++++++++++ doc/Language/containers.pod6 | 4 +- doc/Language/faq.pod6 | 35 ++- doc/Language/functions.pod6 | 12 +- doc/Language/glossary.pod6 | 6 +- doc/Language/grammar_tutorial.pod6 | 10 +- doc/Language/hashmap.pod6 | 8 +- doc/Language/io-guide.pod6 | 18 +- doc/Language/iterating.pod6 | 4 +- doc/Language/list.pod6 | 30 +- doc/Language/modules.pod6 | 6 +- doc/Language/nativetypes.pod6 | 10 +- doc/Language/numerics.pod6 | 18 +- doc/Language/operators.pod6 | 4 +- doc/Language/performance.pod6 | 12 +- doc/Language/pod.pod6 | 12 +- doc/Language/pragmas.pod6 | 8 +- doc/Language/quoting.pod6 | 8 +- doc/Language/rb-nutshell.pod6 | 18 +- doc/Language/regexes.pod6 | 42 +-- doc/Language/subscripts.pod6 | 26 +- doc/Language/syntax.pod6 | 10 +- doc/Language/typesystem.pod6 | 10 +- 25 files changed, 639 insertions(+), 170 deletions(-) create mode 100755 doc/Language/classtut.raku diff --git a/doc/Language/5to6-nutshell.pod6 b/doc/Language/5to6-nutshell.pod6 index 1f0c4d2ad..a41925c85 100644 --- a/doc/Language/5to6-nutshell.pod6 +++ b/doc/Language/5to6-nutshell.pod6 @@ -1518,7 +1518,7 @@ In Raku this is similar, one merely needs to change a number! As you probably guessed, you just need to use X|PERL6LIB>: =for code :lang -$ PERL6LIB="/some/module/lib" raku program.p6 +$ PERL6LIB="/some/module/lib" raku program.raku In Perl 5 one uses the ':' (colon) as a directory separator for C, but in Raku one uses the ',' (comma). For example: @@ -1878,4 +1878,4 @@ live on GitHub. An online converter may become available at some point. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/classtut.pod6 b/doc/Language/classtut.pod6 index 16691a1cd..da206bca6 100644 --- a/doc/Language/classtut.pod6 +++ b/doc/Language/classtut.pod6 @@ -667,7 +667,7 @@ defined in the Employee class as though they were from the Programmer class. =begin code :preamble my $programmer = Programmer.new( salary => 100_000, - known_languages => , + known_languages => , favorite_editor => 'vim' ); @@ -709,8 +709,8 @@ my $cook = Cook.new( ); $cook.cook( 'pizza' ); # OUTPUT: «Cooking pizza␤» -say $cook.utensils.perl; # OUTPUT: «["spoon", "ladle", "knife", "pan"]␤» -say $cook.cookbooks.perl; # OUTPUT: «["The Joy of Cooking"]␤» +say $cook.utensils.raku; # OUTPUT: «["spoon", "ladle", "knife", "pan"]␤» +say $cook.cookbooks.raku; # OUTPUT: «["The Joy of Cooking"]␤» say $cook.salary; # OUTPUT: «40000␤» my $baker = Baker.new( @@ -720,8 +720,8 @@ my $baker = Baker.new( ); $baker.cook('brioche'); # OUTPUT: «Baking a tasty brioche␤» -say $baker.utensils.perl; # OUTPUT: «["self cleaning oven"]␤» -say $baker.cookbooks.perl; # OUTPUT: «["The Baker's Apprentice"]␤» +say $baker.utensils.raku; # OUTPUT: «["self cleaning oven"]␤» +say $baker.cookbooks.raku; # OUTPUT: «["The Baker's Apprentice"]␤» say $baker.salary; # OUTPUT: «50000␤» =end code @@ -753,7 +753,7 @@ my $geek = GeekCook.new( books => 'Learning Raku', utensils => ('stainless steel pot', 'knife', 'calibrated oven'), favorite_editor => 'MacVim', - known_languages => + known_languages => ); $geek.cook('pizza'); @@ -807,7 +807,7 @@ my Programmer $o .= new; if $o ~~ Employee { say "It's an employee" }; say $o ~~ GeekCook ?? "It's a geeky cook" !! "Not a geeky cook"; say $o.^name; -say $o.perl; +say $o.raku; say $o.^methods(:local)».name.join(', '); =end code @@ -829,13 +829,13 @@ C. The call C<$o.^name> tells us the type of C<$o>: in this case C. -C<$o.perl> returns a string that can be executed as Perl code, and +C<$o.raku> returns a string that can be executed as Raku code, and reproduces the original object C<$o>. While this does not work perfectly in all cases, it is very useful for debugging simple objects. N at some point.> +to be handled correctly by C<.raku> at some point.> X<|^methods> C<$o.^methods(:local)> produces a list of Ls that can be called on C<$o>. The C<:local> named argument limits the returned methods to @@ -856,7 +856,7 @@ unsurprisingly returns the class name. Introspection is very useful for debugging and for learning the language and new libraries. When a function or method returns an object you don't know about, by finding its type with C<.^name>, seeing a construction recipe -for it with C<.perl>, and so on, you'll get a good idea of what its return +for it with C<.raku>, and so on, you'll get a good idea of what its return value is. With C<.^methods>, you can learn what you can do with the class. But there are other applications too. For instance, a routine that serializes @@ -906,4 +906,4 @@ it in a narrative way. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/classtut.raku b/doc/Language/classtut.raku new file mode 100755 index 000000000..1431b805f --- /dev/null +++ b/doc/Language/classtut.raku @@ -0,0 +1,472 @@ +#!/usr/bin/env raku + +#=begin code +class Point { + has Int $.x; + has Int $.y; +} + +class Rectangle { + has Point $.lower; + has Point $.upper; + + method area() returns Int { + ($!upper.x - $!lower.x) * ( $!upper.y - $!lower.y); + } +} + +# Create a new Rectangle from two Points +my $r = Rectangle.new(lower => Point.new(x => 0, y => 0), + upper => Point.new(x => 10, y => 10)); + +say $r.area(); # OUTPUT: «100␤» +#=end code + +#=begin code +# Example taken from +# https://medium.freecodecamp.org/a-short-overview-of-object-oriented-software-design-c7aa0a622c83 +class Hero { + has @!inventory; + has Str $.name; + submethod BUILD( :$name, :@inventory ) { + $!name = $name; + @!inventory = @inventory + } + + method act { + return @!inventory.pick; + } +} +my $hero = Hero.new(:name('Þor'), + :inventory(['Mjölnir','Chariot','Bilskirnir'])); +say $hero.act; +#=end code + + +#=begin code +class Task { + has &!callback; + has Task @!dependencies; + has Bool $.done; + + # Normally doesn't need to be written + method new(&callback, *@dependencies) { + return self.bless(:&callback, :@dependencies); + } + + # BUILD is the equivalent of a constructor in other languages + submethod BUILD(:&!callback, :@!dependencies) { } + + method add-dependency(Task $dependency) { + push @!dependencies, $dependency; + } + + method perform() { + unless $!done { + .perform() for @!dependencies; + &!callback(); + $!done = True; + } + } +} + +my $eat = + Task.new({ say 'eating dinner. NOM!' }, + Task.new({ say 'making dinner' }, + Task.new({ say 'buying food' }, + Task.new({ say 'making some money' }), + Task.new({ say 'going to the store' }) + ), + Task.new({ say 'cleaning kitchen' }) + ) + ); + +$eat.perform(); +#=end code + + +=begin code +class Str-with-ID is Str { + my $.counter = 0; + has Str $.string; + has Int $.ID; + + method TWEAK() { + $!ID = $.counter++; + } +} + +say Str-with-ID.new(string => 'First').ID; # OUTPUT: «0» +say Str-with-ID.new(string => 'Second').ID; # OUTPUT: «1» +=end code + + +=begin code +my $in_destructor = 0; + +class Foo { + submethod DESTROY { $in_destructor++ } +} + +my $foo; +for 1 .. 6000 { + $foo = Foo.new(); +} + +say "DESTROY called $in_destructor times"; +=end code + + +#=begin code +say Int.DEFINITE; # OUTPUT: «False␤» (type object) +say 426.DEFINITE; # OUTPUT: «True␤» (instance) + +class Foo {}; +say Foo.DEFINITE; # OUTPUT: «False␤» (type object) +say Foo.new.DEFINITE; # OUTPUT: «True␤» (instance) +#=end code + +#=begin code +multi foo (Int:U) { "It's a type object!" } +multi foo (Int:D) { "It's an instance!" } +say foo Int; # OUTPUT: «It's a type object!␤» +say foo 42; # OUTPUT: «It's an instance!␤» +#=end code + + +=for code :preamble +has Task @!dependencies; + + +=for code +has Bool $.done; + + +=begin code +has Bool $!done; +method done() { return $!done } +=end code + + +=for code +has Bool $.done is rw; + +=for code +has Bool $.done = False; + +=begin code :preamble +has Task @!dependencies; +has $.ready = not @!dependencies; +=end code + +#=begin code +class a-class { + has $.an-attribute is rw; +} +say (a-class.new.an-attribute = "hey"); # OUTPUT: «hey␤» +#=end code + + +#=begin code +class Str-with-ID is Str { + my $counter = 0; + our $hierarchy-counter = 0; + has Str $.string; + has Int $.ID; + + method TWEAK() { + $!ID = $counter++; + $hierarchy-counter++; + } + +} + +class Str-with-ID-and-tag is Str-with-ID { + has Str $.tag; +} + +say Str-with-ID.new(string => 'First').ID; # OUTPUT: «0␤» +say Str-with-ID.new(string => 'Second').ID; # OUTPUT: «1␤» +say Str-with-ID-and-tag.new( string => 'Third', tag => 'Ordinal' ).ID; +# OUTPUT: «2␤» +say $Str-with-ID::hierarchy-counter; # OUTPUT: «4␤» +#=end code + + +=begin code +class Singleton { + my Singleton $instance; + method new {!!!} + submethod instance { + $instance = Singleton.bless unless $instance; + $instance; + } +} +=end code + + +=begin code :preamble +class HaveStaticAttr { + my Foo $.foo = some_complicated_subroutine; +} +=end code + + +=begin code :skip-test +method add-dependency(Task $dependency) { + push @!dependencies, $dependency; +} +=end code + + +=begin code :skip-test +method perform() { + unless $!done { + .perform() for @!dependencies; + &!callback(); + $!done = True; + } +} +=end code + + +=begin code +class B {...} + +class C { + trusts B; + has $!hidden = 'invisible'; + method !not-yours () { say 'hidden' } + method yours-to-use () { + say $!hidden; + self!not-yours(); + } +} + +class B { + method i-am-trusted () { + my C $c.=new; + $c!C::not-yours(); + } +} + +C.new.yours-to-use(); # the context of this call is GLOBAL, and not trusted by C +B.new.i-am-trusted(); +=end code + + +=begin code +method new(&callback, *@dependencies) { + return self.bless(:&callback, :@dependencies); +} +=end code + + +=begin code :preamble +submethod BUILD(:&!callback, :@!dependencies) { } +=end code + + +=begin code +has &!callback; +has @!dependencies; +has Bool ($.done, $.ready); +submethod BUILD( + :&!callback, + :@!dependencies, + :$!done = False, + :$!ready = not @!dependencies, + ) { } +=end code + + +=for code :preamble +my $eat = Task.new({ say 'eating dinner. NOM!' }); + + +=begin code :preamble +my $eat = + Task.new({ say 'eating dinner. NOM!' }, + Task.new({ say 'making dinner' }, + Task.new({ say 'buying food' }, + Task.new({ say 'making some money' }), + Task.new({ say 'going to the store' }) + ), + Task.new({ say 'cleaning kitchen' }) + ) + ); +=end code + + +=begin code :lang +making some money +going to the store +buying food +cleaning kitchen +making dinner +eating dinner. NOM! +=end code + +=head1 Inheritance + + +=begin code +class Employee { + has $.salary; +} + +class Programmer is Employee { + has @.known_languages is rw; + has $.favorite_editor; + + method code_to_solve( $problem ) { + return "Solving $problem using $.favorite_editor in " + ~ $.known_languages[0]; + } +} +=end code + +=begin code :preamble +my $programmer = Programmer.new( + salary => 100_000, + known_languages => , + favorite_editor => 'vim' +); + +say $programmer.code_to_solve('halting problem'), + " will get \$ {$programmer.salary()}"; +# OUTPUT: «Solving halting problem using vim in Perl will get $100000␤» +=end code + + +=begin code :preamble +class Cook is Employee { + has @.utensils is rw; + has @.cookbooks is rw; + + method cook( $food ) { + say "Cooking $food"; + } + + method clean_utensils { + say "Cleaning $_" for @.utensils; + } +} + +class Baker is Cook { + method cook( $confection ) { + say "Baking a tasty $confection"; + } +} + +my $cook = Cook.new( + utensils => , + cookbooks => 'The Joy of Cooking', + salary => 40000 +); + +$cook.cook( 'pizza' ); # OUTPUT: «Cooking pizza␤» +say $cook.utensils.raku; # OUTPUT: «["spoon", "ladle", "knife", "pan"]␤» +say $cook.cookbooks.raku; # OUTPUT: «["The Joy of Cooking"]␤» +say $cook.salary; # OUTPUT: «40000␤» + +my $baker = Baker.new( + utensils => 'self cleaning oven', + cookbooks => "The Baker's Apprentice", + salary => 50000 +); + +$baker.cook('brioche'); # OUTPUT: «Baking a tasty brioche␤» +say $baker.utensils.raku; # OUTPUT: «["self cleaning oven"]␤» +say $baker.cookbooks.raku; # OUTPUT: «["The Baker's Apprentice"]␤» +say $baker.salary; # OUTPUT: «50000␤» +=end code + + +=begin code :preamble +class GeekCook is Programmer is Cook { + method new( *%params ) { + push( %params, "Cooking for Geeks" ); + return self.bless(|%params); + } +} + +my $geek = GeekCook.new( + books => 'Learning Raku', + utensils => ('stainless steel pot', 'knife', 'calibrated oven'), + favorite_editor => 'MacVim', + known_languages => +); + +$geek.cook('pizza'); +$geek.code_to_solve('P =? NP'); +=end code + + +=begin code :preamble +class GeekCook { + also is Programmer; + also is Cook; + # ... +} + +role A {}; +role B {}; +class C { + also does A; + also does B; + # ... +} +=end code + + +=begin code :preamble +my Programmer $o .= new; +if $o ~~ Employee { say "It's an employee" }; +say $o ~~ GeekCook ?? "It's a geeky cook" !! "Not a geeky cook"; +say $o.^name; +say $o.raku; +say $o.^methods(:local)».name.join(', '); +=end code + +=begin code :lang +It's an employee +Not a geeky cook +Programmer +Programmer.new(known_languages => ["Perl", "Python", "Pascal"], + favorite_editor => "gvim", salary => "too small") +code_to_solve, known_languages, favorite_editor +=end code + + +=for code :preamble +say $o.^attributes.join(', '); +say $o.^parents.map({ $_.^name }).join(', '); + + +=begin code +class Cook { + has @.utensils is rw; + has @.cookbooks is rw; + + method cook( $food ) { + return "Cooking $food"; + } + + method clean_utensils { + return "Cleaning $_" for @.utensils; + } + + multi method gist(Cook:U:) { '⚗' ~ self.^name ~ '⚗' } + multi method gist(Cook:D:) { + '⚗ Cooks with ' ~ @.utensils.join( " ‣ ") ~ ' using ' + ~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") } +} + +my $cook = Cook.new( + utensils => , + cookbooks => ['Cooking for geeks','The French Chef Cookbook']); + +say Cook.gist; # OUTPUT: «⚗Cook⚗» +say $cook.gist; # OUTPUT: «⚗ Cooks with spoon ‣ ladle ‣ knife ‣ pan using «Cooking for geeks» and «The French Chef Cookbook»␤» +=end code diff --git a/doc/Language/containers.pod6 b/doc/Language/containers.pod6 index 8b8d49a5e..430943e71 100644 --- a/doc/Language/containers.pod6 +++ b/doc/Language/containers.pod6 @@ -326,7 +326,7 @@ self-referential structures. my @a; @a[0] = @a; - put @a.perl; + put @a.raku; # OUTPUT: «((my @Array_75093712) = [@Array_75093712,])␤» Although Raku does not prevent you from creating and using self-referential @@ -418,4 +418,4 @@ captures|/type/Signature#Type_captures> to work with types in Raku. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/faq.pod6 b/doc/Language/faq.pod6 index ee54dc569..e05cf925c 100644 --- a/doc/Language/faq.pod6 +++ b/doc/Language/faq.pod6 @@ -6,8 +6,8 @@ =head1 General -X<|Rakudo, Raku and Perl 6 (FAQ)> -=head2 What's the difference between Raku, Rakudo and Perl 6? +X<|Rakudo, Raku, and Perl 6 (FAQ)> +=head2 What's the difference between Raku, Rakudo, and Perl 6? Properly speaking, L is an implementation of Raku. It's currently the one that's being developed, but there have been other @@ -308,8 +308,7 @@ X<|Data::Dumper (FAQ)> Typical options are to use the L routine that uses the L method which gives the "gist" of the object being dumped. More detailed output can be obtained by calling the -L method (soon to be deprecated in favor of C<$obj.raku>, -available since the Rakudo 2019.11 release) that typically returns an object's +L method that typically returns an object's representation in L-able code. If you're using the L implementation, you can use @@ -321,7 +320,7 @@ Examples: =begin code :ok-test
my $foo = %( foo => 'bar' ); -say $foo.perl; # OUTPUT: «${:foo("bar")}␤» +say $foo.raku; # OUTPUT: «${:foo("bar")}␤» say $foo; # OUTPUT: «{foo => bar}␤» # non-standard routine available in rakudo implementation: @@ -678,7 +677,7 @@ about the object deemed unimportant to understanding the essence of the object. Or phrased differently, C<$obj.Str> gives a string representation, C<$obj.gist> provides a short summary of that object suitable for -fast recognition by a human, and C<$obj.perl> (C<$obj.raku>) gives a Raku-ish +fast recognition by a human, and C<$obj.raku> gives a Raku-ish representation from which the object could be re-created. For example, when the C method is invoked on a type object, also known @@ -695,7 +694,7 @@ say $x; # OUTPUT: «(Date)␤» If you'd like to show a debugging version of an object, it is probably better to use the L«rakudo-specific C
routine|/programs/01-debugging#Dumper_function_dd». -It essentially does a C<$obj.perl> (C<$obj.raku>) and shows that on STDERR rather than +It essentially does a C<$obj.raku> and shows that on STDERR rather than STDOUT, so it won't interfere with any "normal" output of your program. In short, C is optimized for casual human interpretation, C
is optimized @@ -706,18 +705,18 @@ C is thus a hybrid of C and C; like C, it calls the C method on the object. And like C, it adds a newline at the end of the output. -=head2 What's the difference between C and C ? +=head2 What's the difference between C and C? C, C and C introduce regexes, but with slightly different semantics. -C implies the C<:ratchet> or C<:r> modifier, which prevents the +C implies the C<:ratchet> or C<:r> modifier which prevents the rule from backtracking. C implies both the C<:ratchet> and C<:sigspace> (short C<:s>) modifier, which means a rule doesn't backtrace, and it treats whitespace in the text of the regex as C«<.ws>» calls (i.e., -matches whitespace, which is optional except between two word +it matches whitespace, which is optional except between two word characters). Whitespace at the start of the regex and at the start of each branch of an alternation is ignored. @@ -819,8 +818,8 @@ that the higher number might indicate on other languages. The short answer is that it was Larry's choice under L. -The community considers Perl 5 and Raku sister languages - they have -a lot in common, address many of the same problem spaces, but Raku is not +The community considers Perl 5 and Raku sister languages--they have +a lot in common and address many of the same problem spaces--but Raku is not intended to replace Perl 5. In fact, both languages interoperate with each other. @@ -975,7 +974,7 @@ among its users. See also "camel case" and "snake case": L.) =item Raku's mottos remain the same as they have been for Perl all along: -“Perl is different. In a nutshell, Perl is designed to make the easy jobs easy, +“[Raku] is different. In a nutshell, [Raku] is designed to make the easy jobs easy, without making the hard jobs impossible.” and “There Is More Than One Way To Do It”. Now with even more -Ofun added. @@ -1025,9 +1024,9 @@ for my $i (1..1_000_000) { 1; -# Another Perl 5 version that offers bare-bones set of features -# compared to Moose/Raku's version but those are not needed in this -# specific, simple program anyway. +# Another Perl 5 version that offers a bare-bones set of features +# compared to Moose/Raku's version (but those are not needed in this +# specific, simple program anyway): package Foo; use Mojo::Base -base; @@ -1043,7 +1042,7 @@ for my $i (1..1_000_000) { You might want to use this program for comparing performance, too. It works under both languages, as long as C is used for invocation for -Perl 5. +Perl 5: =begin code my ($prev, $current) = (1, 0); @@ -1056,4 +1055,4 @@ print $current; =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/functions.pod6 b/doc/Language/functions.pod6 index 963f40905..c7a066b1f 100644 --- a/doc/Language/functions.pod6 +++ b/doc/Language/functions.pod6 @@ -203,7 +203,7 @@ L. Destructuring can be used to untangle multiple return values. sub a { 42, 'answer' }; - put a.perl; + put a.raku; # OUTPUT: «(42, "answer")␤» my ($n, $s) = a; @@ -211,7 +211,7 @@ values. # OUTPUT: «answer 42␤» sub b { .Capture }; - put b.perl; + put b.raku; # OUTPUT: «\("a", "b", "c")␤» =head2 Return type constraints @@ -622,11 +622,11 @@ pragma C to prevent inlining to allow wrapping at runtime. } sub wrap-to-debug(&c){ - say "wrapping {&c.name} with arguments {&c.signature.perl}"; + say "wrapping {&c.name} with arguments {&c.signature.raku}"; &c.wrap: sub (|args){ note "calling {&c.name} with {args.gist}"; my \ret-val := callwith(|args); - note "returned from {&c.name} with return value {ret-val.perl}"; + note "returned from {&c.name} with return value {ret-val.raku}"; ret-val } } @@ -1059,7 +1059,7 @@ say Version.new('1.0.2') # OUTPUT: v1.0.2 =begin code class LoggedVersion is Version { method new(|c) { - note "New version object created with arguments " ~ c.perl; + note "New version object created with arguments " ~ c.raku; nextsame; } } @@ -1159,4 +1159,4 @@ for your script. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/glossary.pod6 b/doc/Language/glossary.pod6 index e0f3c64ea..234fd712f 100644 --- a/doc/Language/glossary.pod6 +++ b/doc/Language/glossary.pod6 @@ -392,7 +392,7 @@ C is C. } my $an_instance = A.new; - say $an_instance.defined.perl;# defined($an_instance) works too. + say $an_instance.defined.raku;# defined($an_instance) works too. To put things another way, a class contains the blueprints of methods and attributes, and an instance carries it into the real world. @@ -1128,7 +1128,7 @@ codes. For example: =begin pod C =end pod -say $=pod[0].contents[0].contents.perl; +say $=pod[0].contents[0].contents.raku; =end code The output will be: @@ -1262,4 +1262,4 @@ L. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/grammar_tutorial.pod6 b/doc/Language/grammar_tutorial.pod6 index 42b5c0ce3..d3f851d7c 100644 --- a/doc/Language/grammar_tutorial.pod6 +++ b/doc/Language/grammar_tutorial.pod6 @@ -103,9 +103,9 @@ grammar G { } my $match = G.parse("Þor is mighty"); -say $match.perl; # OUTPUT: «Match.new(made => Any, pos => 13, orig => "Þor is mighty",...» -say $/.perl; # OUTPUT: «Match.new(made => Any, pos => 13, orig => "Þor is mighty",...» -say $/.perl; +say $match.raku; # OUTPUT: «Match.new(made => Any, pos => 13, orig => "Þor is mighty",...» +say $/.raku; # OUTPUT: «Match.new(made => Any, pos => 13, orig => "Þor is mighty",...» +say $/.raku; # OUTPUT: «Match.new(made => Any, pos => 3, orig => "Þor is mighty", hash => Map.new(()), list => (), from => 0)␤» =end code @@ -708,7 +708,7 @@ a regex item. Hopefully this has helped introduce you to the grammars in Raku and shown you how grammars and grammar action classes work together. For more information, -check out the more advanced L. +check out the more advanced L. For more grammar debugging, see L. This provides @@ -717,4 +717,4 @@ tokens. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/hashmap.pod6 b/doc/Language/hashmap.pod6 index 0396202ea..4b53c5a86 100644 --- a/doc/Language/hashmap.pod6 +++ b/doc/Language/hashmap.pod6 @@ -104,7 +104,7 @@ which is used to indicate they are Associative. Hash and map elements are accessed by key via the C<{ }> postcircumfix operator: - say %*ENV{'HOME', 'PATH'}.perl; + say %*ENV{'HOME', 'PATH'}.raku; # OUTPUT: «("/home/camelia", "/usr/bin:/sbin:/bin")␤» The general L rules apply providing shortcuts @@ -244,8 +244,8 @@ Only use curly braces for creating Blocks. You can assign to multiple keys at the same time with a slice. - my %h; %h = 2 xx *; %h.perl.say; # OUTPUT: «{:a(2), :b(2), :c(2)}␤» - my %h; %h = ^3; %h.perl.say; # OUTPUT: «{:a(0), :b(1), :c(2)}␤» + my %h; %h = 2 xx *; %h.raku.say; # OUTPUT: «{:a(2), :b(2), :c(2)}␤» + my %h; %h = ^3; %h.raku.say; # OUTPUT: «{:a(0), :b(1), :c(2)}␤» X<|non-string keys> X<|object hash> @@ -523,4 +523,4 @@ say ''; # OUTPUT: «a => 1; bb => 2;»␤ =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/io-guide.pod6 b/doc/Language/io-guide.pod6 index deb534a73..f40f3fcdf 100644 --- a/doc/Language/io-guide.pod6 +++ b/doc/Language/io-guide.pod6 @@ -43,9 +43,9 @@ on it: It may seem like something is missing here—there is no volume or absolute path involved—but that information is actually present in the object. You can -see it by using L«C<.perl>|/routine/perl» method: +see it by using L«C|/routine/raku» method: - say 'my-file.txt'.IO.perl; + say 'my-file.txt'.IO.raku; # OUTPUT: «IO::Path.new("my-file.txt", :SPEC(IO::Spec::Unix), :CWD("/home/camelia"))␤» The two extra attributes—C and C—specify what type of operating @@ -76,10 +76,10 @@ files that are difficult to store entirely in memory all at the same time, these two routines are for you. =for code -"my-file.txt".IO.spurt: "I ♥ Perl!"; +"my-file.txt".IO.spurt: "I ♥ Raku!"; The code above creates a file named C in the current directory -and then writes text C into it. If Raku is your first language, +and then writes text C into it. If Raku is your first language, celebrate your accomplishment! Try to open the file you created with a text editor to verify what you wrote with your program. If you already know some other language, you may be wondering if this guide missed anything like @@ -137,7 +137,7 @@ We've seen in previous sections that writing stuff to files is a single-line of code in Raku. Reading from them, is similarly easy: =for code -say 'my-file.txt'.IO.slurp; # OUTPUT: «I ♥ Perl!␤» +say 'my-file.txt'.IO.slurp; # OUTPUT: «I ♥Raku!␤» say 'my-file.txt'.IO.slurp: :bin; # OUTPUT: «Buf[uint8]:0x<49 20 e2 99 a5 20 50 65 72 6c 21>␤» The L«C<.slurp>|/routine/slurp» method reads entire contents of the file @@ -153,13 +153,13 @@ L«C<.lines>|/type/IO::Path#method_lines» that lazily read the file in smaller chunks and return L objects that (by default) don't keep already-consumed values around. -Here's an example that finds lines in a text file that mention Perl and prints +Here's an example that finds lines in a text file that mention Raku and prints them out. Despite the file itself being too large to fit into available L, the program will not have any issues running, as the contents are processed in small chunks: =for code -.say for '500-PetaByte-File.txt'.IO.lines.grep: *.contains: 'Perl'; +.say for '500-PetaByte-File.txt'.IO.lines.grep: *.contains: 'Raku'; Here's another example that prints the first 100 words from a file, without loading it entirely: @@ -188,7 +188,7 @@ type, which gives you a lot finer control over what you're doing: =begin code given 'some-file.txt'.IO.open { - say .readchars: 8; # OUTPUT: «I ♥ Perl␤» + say .readchars: 8; # OUTPUT: «I ♥Raku␤» .seek: 1, SeekFromCurrent; say .readchars: 15; # OUTPUT: «I ♥ Programming␤» .close @@ -332,4 +332,4 @@ L«C routine|/routine/indir» for that purpose. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/iterating.pod6 b/doc/Language/iterating.pod6 index 653d88943..c19069e01 100644 --- a/doc/Language/iterating.pod6 +++ b/doc/Language/iterating.pod6 @@ -31,7 +31,7 @@ class DNA does Iterable { }; my @longer-chain = DNA.new('ACGTACGTT'); -say @longer-chain.perl; +say @longer-chain.raku; # OUTPUT: «[("A", "C", "G"), ("T", "A", "C"), ("G", "T", "T")]␤» say @longer-chain».join("").join("|"); #OUTPUT: «ACG|TAC|GTT␤» @@ -149,4 +149,4 @@ possible, functional and concurrent iterating constructs. I Since version 6.d loops can produce a list of values from the values of last statements. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/list.pod6 b/doc/Language/list.pod6 index 49eeab992..ba0174026 100644 --- a/doc/Language/list.pod6 +++ b/doc/Language/list.pod6 @@ -620,12 +620,12 @@ C<@>-sigiled variable has an element type of C, however its default value is an undefined C: my @a; - @a.of.perl.say; # OUTPUT: «Mu␤» - @a.default.perl.say; # OUTPUT: «Any␤» + @a.of.raku.say; # OUTPUT: «Mu␤» + @a.default.raku.say; # OUTPUT: «Any␤» @a[0].say; # OUTPUT: «(Any)␤» my Numeric @n is default(Real); - @n.of.perl.say; # OUTPUT: «Numeric␤» - @n.default.perl.say; # OUTPUT: «Real␤» + @n.of.raku.say; # OUTPUT: «Numeric␤» + @n.default.raku.say; # OUTPUT: «Real␤» @n[0].say; # OUTPUT: «(Real)␤» @@ -639,11 +639,11 @@ kind of C will default to C. The shape can be accessed at runtime via the C method. my @a[2,2]; - say @a.perl; + say @a.raku; # OUTPUT: «Array.new(:shape(2, 2), [Any, Any], [Any, Any])␤» say @a.shape; # OUTPUT: «(2 2)␤» my @just-three[3] = ; - say @just-three.perl; + say @just-three.raku; # OUTPUT: «Array.new(:shape(3,), ["alpha", "beta", "kappa"])␤» Shape will control the amount of elements that can be assigned by dimension: @@ -659,7 +659,7 @@ Arrays (making then mutable in the process). my @a[2;2] = (1,2; 3,4); say @a.Array; # OUTPUT: «[1 2 3 4]␤» @a[1;1] = 42; - say @a.perl; + say @a.raku; # OUTPUT: «Array.new(:shape(2, 2), [1, 2], [3, 42])␤» As the third statement shows, you can assign directly to an element in a shaped @@ -686,11 +686,11 @@ firm understanding of. First, be aware that because itemization in Arrays is assumed, it essentially means that C<$(…)>s are being put around everything that you assign to an -array, if you do not put them there yourself. On the other side, Array.perl -does not put C<$> to explicitly show scalars, unlike List.perl: +array, if you do not put them there yourself. On the other side, Array.raku +does not put C<$> to explicitly show scalars, unlike List.raku: - ((1, 2), $(3, 4)).perl.say; # says "((1, 2), $(3, 4))" - [(1, 2), $(3, 4)].perl.say; # says "[(1, 2), (3, 4)]" + ((1, 2), $(3, 4)).raku.say; # says "((1, 2), $(3, 4))" + [(1, 2), $(3, 4)].raku.say; # says "[(1, 2), (3, 4)]" # ...but actually means: "[$(1, 2), $(3, 4)]" It was decided all those extra dollar signs and parentheses were more of an @@ -701,14 +701,14 @@ Second, remember that these invisible dollar signs also protect against flattening, so you cannot really flatten the elements inside of an Array with a normal call to C or C<.flat>. - ((1, 2), $(3, 4)).flat.perl.say; # OUTPUT: «(1, 2, $(3, 4)).Seq␤» - [(1, 2), $(3, 4)].flat.perl.say; # OUTPUT: «($(1, 2), $(3, 4)).Seq␤» + ((1, 2), $(3, 4)).flat.raku.say; # OUTPUT: «(1, 2, $(3, 4)).Seq␤» + [(1, 2), $(3, 4)].flat.raku.say; # OUTPUT: «($(1, 2), $(3, 4)).Seq␤» Since the square brackets do not themselves protect against flattening, you can still spill the elements out of an Array into a surrounding list using C. - (0, [(1, 2), $(3, 4)], 5).flat.perl.say; # OUTPUT: «(0, $(1, 2), $(3, 4), 5).Seq␤» + (0, [(1, 2), $(3, 4)], 5).flat.raku.say; # OUTPUT: «(0, $(1, 2), $(3, 4), 5).Seq␤» ...the elements themselves, however, stay in one piece. @@ -793,4 +793,4 @@ creature should never be passed back to unsuspecting users. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/modules.pod6 b/doc/Language/modules.pod6 index e9733bf26..16ff1dc40 100644 --- a/doc/Language/modules.pod6 +++ b/doc/Language/modules.pod6 @@ -98,7 +98,7 @@ And then use MyModule; my $class = Class.new(); -say $class.perl; +say $class.raku; =end code =head2 X> @@ -737,7 +737,7 @@ distribution and that you wish to be installed; only module files that are explicitly included here will be installed and available with C or C in other programs. This field is mandatory. -Set C version to the minimum perl version your module works with. This +Set C version to the minimum Raku version your module works with. This field is mandatory. Use C<6.c> if your module is valid for Christmas release and newer ones, use C<6.d> if it requires, at least, the Diwali version. @@ -955,4 +955,4 @@ L. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/nativetypes.pod6 b/doc/Language/nativetypes.pod6 index 3888cf164..e1dfa2db6 100644 --- a/doc/Language/nativetypes.pod6 +++ b/doc/Language/nativetypes.pod6 @@ -88,7 +88,7 @@ they can be shaped: =begin code my str @letter-pairs[10] = 'a'..'j' Z~ 'A'..'J'; -say @letter-pairs.perl; +say @letter-pairs.raku; # OUTPUT: «array[str].new(:shape(10,), ["aA", "bB", "cC", "dD", "eE", "fF", "gG", "hH", "iI", "jJ"])␤» =end code @@ -103,7 +103,7 @@ class Foo { submethod BUILD( :$!numillo = 3.5e0 ) {} }; my $foo = Foo.new; -say $foo.perl; # OUTPUT: «Foo.new(numillo => 3.5e0)␤» +say $foo.raku; # OUTPUT: «Foo.new(numillo => 3.5e0)␤» X<|int8>X<|int16>X<|int32>X<|int64>X<|uint8>X<|uint16>X<|uint32>X<|uint64> @@ -159,7 +159,7 @@ valid type, you can use it in expressions: use NativeCall; my void $nothing; - say $nothing.perl; # OUTPUT: «NativeCall::Types::void␤» + say $nothing.raku; # OUTPUT: «NativeCall::Types::void␤» In practice, it is an C type that can rarely be used by itself, and in fact it is @@ -171,7 +171,7 @@ pointer in C. =begin code :preamble sub malloc( int32 $size --> Pointer[void] ) is native { * }; my Pointer[void] $for-malloc = malloc( 32 ); -say $for-malloc.perl; +say $for-malloc.raku; =end code You can also L Ls to this kind @@ -233,4 +233,4 @@ Which would print the five elements of the array, as it should be expected. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/numerics.pod6 b/doc/Language/numerics.pod6 index af98c989e..d1d534a21 100644 --- a/doc/Language/numerics.pod6 +++ b/doc/Language/numerics.pod6 @@ -86,13 +86,13 @@ L (also known as Keep in mind that output routines like L or L do not try very hard to distinguish between how L types are output and may choose to display a L as an L or a L number. For a more definitive string to -output, use the L method: +output, use the L method: =begin code say 1e0; # OUTPUT: «1␤» say .5e0; # OUTPUT: «0.5␤» -say 1e0.perl; # OUTPUT: «1e0␤» -say .5e0.perl; # OUTPUT: «0.5e0␤» +say 1e0.raku; # OUTPUT: «1e0␤» +say .5e0.raku; # OUTPUT: «0.5e0␤» =end code =head1 C @@ -253,7 +253,7 @@ create your own custom operator: =begin code sub infix:<🙼> { FatRat.new: $^a, $^b } -say (1🙼3).perl; # OUTPUT: «FatRat.new(1, 3)␤» +say (1🙼3).raku; # OUTPUT: «FatRat.new(1, 3)␤» =end code =head2 Printing rationals @@ -261,13 +261,13 @@ say (1🙼3).perl; # OUTPUT: «FatRat.new(1, 3)␤» Keep in mind that output routines like L or L do not try very hard to distinguish between how L types are output and may choose to display a L as an L or a L number. For a more definitive string to -output, use the L method: +output, use the L method: =begin code say 1.0; # OUTPUT: «1␤» say ⅓; # OUTPUT: «0.333333␤» -say 1.0.perl; # OUTPUT: «1.0␤» -say ⅓.perl; # OUTPUT: «<1/3>␤» +say 1.0.raku; # OUTPUT: «1.0␤» +say ⅓.raku; # OUTPUT: «<1/3>␤» =end code For even more information, you may choose to see the L object in @@ -276,7 +276,7 @@ the L, displaying its Bmerator and Bnominator: =begin code say ⅓; # OUTPUT: «0.333333␤» say 4/2; # OUTPUT: «2␤» -say ⅓.perl; # OUTPUT: «<1/3>␤» +say ⅓.raku; # OUTPUT: «<1/3>␤» say <4/2>.nude; # OUTPUT: «(2 1)␤» =end code @@ -773,4 +773,4 @@ types get autoboxed and have the same infectiousness as their boxed variant. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/operators.pod6 b/doc/Language/operators.pod6 index 1ec633ef3..45fc85687 100644 --- a/doc/Language/operators.pod6 +++ b/doc/Language/operators.pod6 @@ -680,7 +680,7 @@ Universal interface for positional access to zero or more elements of a say @alphabet[1]; # OUTPUT: «b␤» say @alphabet[*-1]; # OUTPUT: «z␤» say @alphabet[100]:exists; # OUTPUT: «False␤» - say @alphabet[15, 4, 17, 11].join; # OUTPUT: «perl␤» + say @alphabet[17, 0, 10, 20].join; # OUTPUT: raku␤» say @alphabet[23 .. *].raku; # OUTPUT: «("x", "y", "z")␤» @alphabet[1, 2] = "B", "C"; @@ -3529,4 +3529,4 @@ say [%] (); # OUTPUT: «(exit code 1) No zero-arg meaning for infix:<%>␤ =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/performance.pod6 b/doc/Language/performance.pod6 index 80b9550ab..44239dbbf 100644 --- a/doc/Language/performance.pod6 +++ b/doc/Language/performance.pod6 @@ -19,7 +19,7 @@ Expressions of the form C, where C is a L, provide a great idiom for timing code snippets. -Use the C L<#perl6 channel +Use the C L<#raku channel evalbot|/language/glossary#camelia> to write lines like: =begin code :lang @@ -80,7 +80,7 @@ opening in SQLite. =begin code :lang # create a profile - perl6 --profile=demo.sql -e 'say (^20).combinations(3).elems' + raku --profile=demo.sql -e 'say (^20).combinations(3).elems' # create a SQLite database sqlite3 demo.sqlite @@ -153,7 +153,7 @@ of your code. =head2 Line by line A quick, fun, productive way to try improve code line-by-line is to collaborate -with others using the L<#perl6|/language/glossary#IRC> evalbot +with others using the L<#raku|/language/glossary#IRC> evalbot L. =head2 Routine by routine @@ -229,7 +229,7 @@ there are a number of L Once installed, run the following command in the terminal: =begin code :lang -perl6 --doc=HTML input.pod6 > output.html +raku --doc=HTML input.pod6 > output.html =end code =head2 Markdown @@ -797,7 +797,7 @@ C Once installed, run the following command in the terminal: =begin code :lang -perl6 --doc=Markdown input.pod6 > output.md +raku --doc=Markdown input.pod6 > output.md =end code =head2 Text @@ -807,13 +807,13 @@ C module. Using the terminal, run the following command: =begin code :lang -perl6 --doc=Text input.pod6 > output.txt +raku --doc=Text input.pod6 > output.txt =end code You can omit the C<=Text> portion: =begin code :lang -perl6 --doc input.pod6 > output.txt +raku --doc input.pod6 > output.txt =end code You can even embed Pod6 directly in your program and add the @@ -856,7 +856,7 @@ Here some text for the subsection. for $=pod -> $pod-item { for $pod-item.contents -> $pod-block { - $pod-block.perl.say; + $pod-block.raku.say; } } =end code @@ -870,4 +870,4 @@ Pod::Heading.new(level => 2, config => {}, contents => [Pod::Block::Para.new(con Pod::Block::Para.new(config => {}, contents => ["Here some text for the subsection."]); =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/pragmas.pod6 b/doc/Language/pragmas.pod6 index 62757f5ad..0cfe05289 100644 --- a/doc/Language/pragmas.pod6 +++ b/doc/Language/pragmas.pod6 @@ -27,8 +27,6 @@ and turns on its features if they are optional. =for code :solo use v6; # Load latest supported version (non-PREVIEW). - # Also, useful for producing better errors when accidentally - # executing the program with `perl` instead of `perl6` =for code :solo use v6.c; # Use the "Christmas" version of Raku @@ -287,7 +285,7 @@ Lexically controls whether compile-time warnings generated by the compiler get shown. Enabled by default. =begin code :lang - $ perl6 -e 'say :foo<>.Pair' + $ raku -e 'say :foo<>.Pair' Potential difficulties: Pair with <> really means an empty list, not null string; use :foo('') to represent the null string, or :foo() to represent the empty list more accurately @@ -295,10 +293,10 @@ compiler get shown. Enabled by default. ------> say :foo<>⏏.Pair foo => Nil - $ perl6 -e 'no worries; say :foo<>.Pair' + $ raku -e 'no worries; say :foo<>.Pair' foo => Nil =end code =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/quoting.pod6 b/doc/Language/quoting.pod6 index f27c65d4e..eef31a9da 100644 --- a/doc/Language/quoting.pod6 +++ b/doc/Language/quoting.pod6 @@ -177,7 +177,7 @@ Therefore its volume should be 42 m³! By default, only variables with the C<$> sigil are interpolated normally. This way, when you write C<"documentation@raku.org">, you aren't -interpolating the C<@perl6> variable. If that's what you want to do, append +interpolating the C<@raku> variable. If that's what you want to do, append a C<[]> to the variable name: =begin code :allow @@ -393,11 +393,11 @@ I interpolate variables. Thus say qx{echo "hello $world"} prints simply C. Nevertheless, if you have declared an environment -variable before calling C, this will be available within C, for +variable before calling C, this will be available within C, for instance =begin code :skip-test -WORLD="there" perl6 +WORLD="there" raku > say qx{echo "hello $WORLD"} =end code @@ -532,4 +532,4 @@ expression documentation|/language/regexes>. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/rb-nutshell.pod6 b/doc/Language/rb-nutshell.pod6 index e311ad26b..6cb6887a3 100644 --- a/doc/Language/rb-nutshell.pod6 +++ b/doc/Language/rb-nutshell.pod6 @@ -63,7 +63,7 @@ concepts than in keystrokes. As a result, there are various places in the syntax where whitespace is optional in Ruby, but is either mandatory or forbidden in Raku. Many of those -restrictions are unlikely to concern much real-life Perl code (e.g. whitespace +restrictions are unlikely to concern much real-life Raku code (e.g., whitespace being disallowed between an array variable and its square brackets), but there are a few that will unfortunately conflict with some Ruby hackers' habitual coding styles: @@ -350,13 +350,13 @@ The Raku version above is slightly different in that when it slurps in the arguments into @args, one level of nesting, if any, is automatically removed: =for code -sub foo(*@args) { say @args.perl } +sub foo(*@args) { say @args.raku } foo([1, [2, 3], 4], 5, [6, 7]); # [1, [2, 3], 4, 5, 6, 7] To preserve the structure of the arguments, you can use C<**>: =for code -sub foo(**@args) { say @args.perl } +sub foo(**@args) { say @args.raku } foo([1, [2, 3], 4], 5, [6, 7]); # [[1, [2, 3], 4], 5, [6, 7]] You might want to expand an array into a set of arguments. In Raku this is @@ -1049,7 +1049,7 @@ See L for lots of further details. =head1 Environment variables -=head2 Perl module library path +=head2 Raku module library path In Ruby, one of the environment variables to specify extra search paths for modules is C. @@ -1061,7 +1061,7 @@ In Raku this is similar, you merely needs to change the name. As you probably guessed, you just need to use C: =for code :lang -$ PERL6LIB="/some/module/lib" perl6 program.p6 +$ PERL6LIB="/some/module/lib" raku program.raku As with Ruby, if you don't specify C, you need to specify the library path within the program via the C pragma: @@ -1154,13 +1154,13 @@ sub MAIN ( Int :$length where * > 0, :$filename = 'file.dat', Bool :$verbose ) { =end code =begin code :lang -perl6 example.p6 --file=foo --length=42 --verbose +raku example.raku --file=foo --length=42 --verbose 42 foo Verbosity on -perl6 example.p6 --length=abc +raku example.raku --length=abc Usage: - example.p6 [--length=] [--file=] [--verbose] + example.raku [--length=] [--file=] [--verbose] =end code Note that Raku auto-generates a full usage message on error in @@ -1207,4 +1207,4 @@ answer yet, that will be better than losing the information about a real need. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/regexes.pod6 b/doc/Language/regexes.pod6 index 534315191..39cc14a5c 100644 --- a/doc/Language/regexes.pod6 +++ b/doc/Language/regexes.pod6 @@ -370,16 +370,16 @@ An unescaped dot C<.> in a regex matches any single character. So, these all match: - 'perl' ~~ /per./; # matches the whole string - 'perl' ~~ / per . /; # the same; whitespace is ignored - 'perl' ~~ / pe.l /; # the . matches the r + 'raku' ~~ /rak./; # matches the whole string + 'raku' ~~ / rak . /; # the same; whitespace is ignored + 'raku' ~~ / ra.u /; # the . matches the k 'speller' ~~ / pe.l/; # the . matches the first l while this doesn't match: - 'perl' ~~ /. per /; + 'raku' ~~ /. rak /; -because there's no character to match before C in the target string. +because there's no character to match before C in the target string. Notably C<.> also matches a logical newline C<\n>: @@ -626,7 +626,7 @@ C«<:Ll+:N>» or C«<:Ll+:Number>» or C«<+ :Lowercase_Letter + :Number>». It's also possible to group categories and sets of categories with parentheses; for example: - say $0 if 'perl6' ~~ /\w+(<:Ll+:N>)/ # OUTPUT: «「6」␤» + say $0 if 'hold3' ~~ /\w+(<:Ll+:N>)/ # OUTPUT: «「3」␤» =head2 X«Enumerated character classes and ranges|regex,<[ ]>;regex,<-[ ]>» @@ -1020,21 +1020,21 @@ anchoring the regex match to that position. The C<^> anchor only matches at the start of the string: - say so 'properly' ~~ / perl/; # OUTPUT: «True␤» - say so 'properly' ~~ /^ perl/; # OUTPUT: «False␤» - say so 'perly' ~~ /^ perl/; # OUTPUT: «True␤» - say so 'perl' ~~ /^ perl/; # OUTPUT: «True␤» + say so 'prorakuy' ~~ / raku/; # OUTPUT: «True␤» + say so 'prorakuy' ~~ /^ raku/; # OUTPUT: «False␤» + say so 'rakuy' ~~ /^ raku/; # OUTPUT: «True␤» + say so 'raku' ~~ /^ raku/; # OUTPUT: «True␤» The C<$> anchor only matches at the end of the string: - say so 'use perl' ~~ / perl /; # OUTPUT: «True␤» - say so 'use perl' ~~ / perl $/; # OUTPUT: «True␤» - say so 'perly' ~~ / perl $/; # OUTPUT: «False␤» + say so 'use raku' ~~ / raku /; # OUTPUT: «True␤» + say so 'use raku' ~~ / raku $/; # OUTPUT: «True␤» + say so 'rakuy' ~~ / raku $/; # OUTPUT: «False␤» You can combine both anchors: - say so 'use perl' ~~ /^ perl $/; # OUTPUT: «False␤» - say so 'perl' ~~ /^ perl $/; # OUTPUT: «True␤» + say so 'use raku' ~~ /^ raku $/; # OUTPUT: «False␤» + say so 'raku' ~~ /^ raku $/; # OUTPUT: «True␤» Keep in mind that C<^> matches the start of a B, not the start of a B. Likewise, C<$> matches the end of a B, not the end of @@ -1550,7 +1550,7 @@ attached to C). Regular expressions can also be used to substitute one piece of text for another. You can use this for anything, from correcting a spelling error -(e.g., replacing 'Perl Jam' with 'Pearl Jam'), to reformatting an ISO8601 +(e.g., replacing 'The Beetles' with 'The Beatles'), to reformatting an ISO8601 date from C to C and beyond. Just like the search-and-replace editor's dialog box, the C operator @@ -1856,7 +1856,7 @@ Here's more complete code for parsing C files: %config{ $section
[0] } = %section; } } - say %config.perl; + say %config.raku; # OUTPUT: «{:passwords(${:jack("password1"), :joy("muchmoresecure123")}), # :quotas(${:jack("123"), :joy("42")})}» @@ -2520,9 +2520,9 @@ C<:sigspace> modifier for the regex, and in addition, copies the whitespace from the matched string to the replacement string: =begin code -say S:samespace/a ./c d/.perl given "a b"; # OUTPUT: «"c d"» -say S:samespace/a ./c d/.perl given "a\tb"; # OUTPUT: «"c\td"» -say S:samespace/a ./c d/.perl given "a\nb"; # OUTPUT: «"c\nd"» +say S:samespace/a ./c d/.raku given "a b"; # OUTPUT: «"c d"» +say S:samespace/a ./c d/.raku given "a\tb"; # OUTPUT: «"c\td"» +say S:samespace/a ./c d/.raku given "a\nb"; # OUTPUT: «"c\nd"» =end code The C syntactic form is a shorthand for @@ -2802,4 +2802,4 @@ provides useful information on how to avoid common pitfalls when writing regexes and grammars. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/subscripts.pod6 b/doc/Language/subscripts.pod6 index 01695aaed..589050db2 100644 --- a/doc/Language/subscripts.pod6 +++ b/doc/Language/subscripts.pod6 @@ -79,15 +79,15 @@ Hash subscripts do not do the same thing as C«=>». The default C has been made to behave the way new users have come to expect from using other languages, and for general ease of use. On a default C, subscripts coerce keys into strings, as long as -those keys produce something C. You can use C<.perl> on a +those keys produce something C. You can use C<.raku> on a collection to be sure whether the keys are strings or objects: - ( 1 => 1 ).perl.say; # OUTPUT: «1 => 1␤» - my %h; %h{1} = 1; say %h.perl; # OUTPUT: «{ "1" => 1 }␤» - ( 1/2 => 1 ).perl.say; # OUTPUT: «0.5 => 1␤» - my %h; %h{1/2} = 1; say %h.perl; # OUTPUT: «{ "0.5" => 1 }␤» - ( pi => 1 ).perl.say; # OUTPUT: «:pi(1)␤» - my %h; %h{pi} = 1; say %h.perl; # OUTPUT: «{ "3.14159265358979" => 1 }␤» + ( 1 => 1 ).raku.say; # OUTPUT: «1 => 1␤» + my %h; %h{1} = 1; say %h.raku; # OUTPUT: «{ "1" => 1 }␤» + ( 1/2 => 1 ).raku.say; # OUTPUT: «0.5 => 1␤» + my %h; %h{1/2} = 1; say %h.raku; # OUTPUT: «{ "0.5" => 1 }␤» + ( pi => 1 ).raku.say; # OUTPUT: «:pi(1)␤» + my %h; %h{pi} = 1; say %h.raku; # OUTPUT: «{ "3.14159265358979" => 1 }␤» While the invisible quotes around single names is built into C«=>», string conversion is not built into the curly braces: it is a behavior @@ -96,11 +96,11 @@ do so: =for code my %h := MixHash.new; -%h{pi} = 1; %h.perl.say; # OUTPUT: «(3.14159265358979e0=>1).MixHash␤» +%h{pi} = 1; %h.raku.say; # OUTPUT: «(3.14159265358979e0=>1).MixHash␤» (Any name that C«=>» would convert to a string can also be used to build a pair using "adverbial notation" and will appear that way when viewed -through C<.perl>, which is why we see C<:pi(1)> above.) +through C<.raku>, which is why we see C<:pi(1)> above.) =head2 Applying subscripts @@ -203,7 +203,7 @@ For positional slices, you can mix normal indices with L ones: my @alphabet = 'a' .. 'z'; - say @alphabet[15, 4, *-9, 11].perl; # OUTPUT: «("p", "e", "r", "l")␤» + say @alphabet[15, 4, *-9, 11].raku; # OUTPUT: «("p", "e", "r", "l")␤» In the C<*-number> construct above, C<*> indicates the end of the array as explained above in the L @@ -412,7 +412,7 @@ my $beatles; $beatles{"White Album"}[0] = "Back in the U.S.S.R."; # autovivification! -say $beatles.perl; # OUTPUT: «${"White Album" => $["Back in the U.S.S.R."]}␤» +say $beatles.raku; # OUTPUT: «${"White Album" => $["Back in the U.S.S.R."]}␤» =end code C<$beatles> started out undefined, but became a L object @@ -737,7 +737,7 @@ behavior, can be indexed like a hash: $request.header{'Accept-' X~ } = ; $request.header.push('Accept-Language' => "fr"); # like .push on a Hash - say $request.header.perl; # OUTPUT: «["en", "fr"]␤» + say $request.header.raku; # OUTPUT: «["en", "fr"]␤» my $rawheader = $request.header.Str; # stringify according to HTTP spec =end code @@ -1103,4 +1103,4 @@ the object for the first time. Should return the invocant. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/syntax.pod6 b/doc/Language/syntax.pod6 index 0b798780f..a299180a2 100644 --- a/doc/Language/syntax.pod6 +++ b/doc/Language/syntax.pod6 @@ -721,16 +721,16 @@ clone and flatten it. If you want an C with just 1 element that is an C, ensure to use a comma after it: my @a = 1, 2; - say [@a].perl; # OUTPUT: «[1, 2]␤» - say [@a,].perl; # OUTPUT: «[[1, 2],]␤» + say [@a].raku; # OUTPUT: «[1, 2]␤» + say [@a,].raku; # OUTPUT: «[[1, 2],]␤» The C constructor does not flatten other types of contents. Use the L prefix operator (C<|>) to flatten the needed items: my @a = 1, 2; - say [@a, 3, 4].perl; # OUTPUT: «[[1, 2], 3, 4]␤» - say [|@a, 3, 4].perl; # OUTPUT: «[1, 2, 3, 4]␤» + say [@a, 3, 4].raku; # OUTPUT: «[[1, 2], 3, 4]␤» + say [|@a, 3, 4].raku; # OUTPUT: «[1, 2, 3, 4]␤» L type can be explicitly created from an array literal declaration without a coercion from Array, using B @@ -1021,4 +1021,4 @@ You can also wrap a unary operator with a hyper operator. =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku diff --git a/doc/Language/typesystem.pod6 b/doc/Language/typesystem.pod6 index 11651109e..dddd4e7fe 100644 --- a/doc/Language/typesystem.pod6 +++ b/doc/Language/typesystem.pod6 @@ -269,7 +269,7 @@ L«sub-signatures|/type/Signature#Sub-signatures» are supported. class Magic { method FALLBACK ($name, |c(Int, Str)) { - put "$name called with parameters {c.perl}" } + put "$name called with parameters {c.raku}" } }; Magic.new.simsalabim(42, "answer"); @@ -401,7 +401,7 @@ methods to provide an interface for introspection and coercion to basic types. class A { multi method from-a(){ 'A::from-a' } } - say A.new.^parents(:all).perl; + say A.new.^parents(:all).raku; # OUTPUT: «(Any, Mu)␤» class B { @@ -504,7 +504,7 @@ C. A forward declaration of the trusted class may be required. trusts B; has $!foo; method !foo { return-rw $!foo } - method perl { "A.new(foo => $!foo)" } + method raku { "A.new(foo => $!foo)" } }; class B { has A $.a .= new; @@ -794,7 +794,7 @@ the keys. enum E ; my @keys = E::.values; - say @keys.map: *.perl; + say @keys.map: *.raku; # OUTPUT: «(E::one E::two)␤» With the use of B<()> parentheses, an enum can be defined using any @@ -979,4 +979,4 @@ subset C where ::('YourModule::C'); =end pod -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 +# vim: expandtab softtabstop=4 shiftwidth=4 ft=raku