Changeset 17701
- Timestamp:
- 09/06/07 19:43:34 (15 months ago)
- Files:
-
- 56 modified
-
docs/Perl6/API/Scalar.pod (modified) (1 diff)
-
docs/Perl6/Overview/File.pod (modified) (2 diffs)
-
docs/Perl6/Spec/Functions.pod (modified) (1 diff)
-
docs/notes/precompilation_cache.pod (modified) (1 diff)
-
docs/notes/unicode_draft (modified) (1 diff)
-
docs/other/porting_howto (modified) (1 diff)
-
docs/tutorial/ch04_basic_syntax.pod (modified) (11 diffs)
-
docs/tutorial/ch07_grammars.pod (modified) (1 diff)
-
examples/advocacy/motd-i.pl (modified) (1 diff)
-
examples/advocacy/motd.pl (modified) (1 diff)
-
examples/cookbook/07file-access/07-01opening_file.pl (modified) (2 diffs)
-
examples/cookbook/07file-access/07-04making_perl_report_filenames_in_error_messages.pl (modified) (1 diff)
-
examples/games/hangman.pl (modified) (1 diff)
-
examples/games/hangman.pod (modified) (1 diff)
-
examples/golf/tsanta.pl (modified) (4 diffs)
-
examples/irclog2html.pl (modified) (2 diffs)
-
examples/matrix.pl (modified) (1 diff)
-
examples/naive_bayesian/naive_bayesian.pl (modified) (3 diffs)
-
examples/network/hangmanbot.pl (modified) (1 diff)
-
examples/p6explain/p6explain (modified) (1 diff)
-
examples/password-manager.p6 (modified) (4 diffs)
-
examples/perl5/cpan-upload.pl (modified) (1 diff)
-
examples/perldoc.pl (modified) (4 diffs)
-
examples/qotw/019r/qotw-regular-19.pl (modified) (1 diff)
-
examples/qotw/024r/qotw-regular-24.pl (modified) (2 diffs)
-
examples/rpn/p6/Rpn.pm (modified) (1 diff)
-
examples/rules/rpn_calc.pl (modified) (1 diff)
-
examples/rules/unitsdat-grammar.pm (modified) (1 diff)
-
ext/Getopt-Std/lib/Getopt/Std.pm (modified) (1 diff)
-
misc/old_pugs_perl5_backend/PIL-Run/lib/PIL/Run/PrimP5.pm (modified) (1 diff)
-
misc/pX/Common/Pugs-Compiler-Perl6/lib/Pugs/Grammar/Infix.pm (modified) (1 diff)
-
misc/pX/Common/Pugs-Compiler-Perl6/moose-3.pl (modified) (1 diff)
-
misc/pX/Common/Pugs-Emitter-Perl6-Perl5-2/lib/Pugs/Emitter/Perl6/Perl5.pm (modified) (1 diff)
-
misc/pX/Common/Pugs-Emitter-Perl6-Perl5/lib/Pugs/Emitter/Perl6/Perl5.pm (modified) (1 diff)
-
misc/pX/Common/redsix/redsix (modified) (2 diffs)
-
misc/pX/Common/redsix/redsix_snapshot.rb (modified) (2 diffs)
-
perl5/PIL2JS/lib6/Prelude/JS/Bool.pm (modified) (1 diff)
-
perl5/PIL2JS/lib6/Prelude/JS/Operators.pm (modified) (1 diff)
-
perl5/Pugs-Compiler-Perl6/lib/Pugs/Emitter/Perl6/Perl5.pm (modified) (1 diff)
-
perl5/Pugs-Compiler-Perl6/lib/Pugs/Grammar/Infix.pm (modified) (1 diff)
-
perl5/Pugs-Compiler-Perl6/moose-3.pl (modified) (1 diff)
-
src/Pugs/Compile.hs (modified) (1 diff)
-
src/Pugs/Compile/PIL2.hs (modified) (1 diff)
-
src/Pugs/Parser/Operator.hs (modified) (2 diffs)
-
src/Pugs/Prim.hs (modified) (2 diffs)
-
src/perl6/Prelude.pm (modified) (1 diff)
-
src/perl6/STD.pm (modified) (6 diffs)
-
t/builtins/io/dir.t (modified) (2 diffs)
-
t/builtins/io/getc.t (modified) (1 diff)
-
t/builtins/io/slurp.t (modified) (1 diff)
-
t/builtins/system/chmod.t (modified) (1 diff)
-
t/examples/golfex.t (modified) (1 diff)
-
t/operators/reduce-metaop.t (modified) (1 diff)
-
t/operators/short_circuit.t (modified) (3 diffs)
-
t/packages/require_and_use.t (modified) (1 diff)
-
t/unspecced/precompile.t (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/Perl6/API/Scalar.pod
r12817 r17701 57 57 warning in doing so. There are two ways to determine if a 58 58 value equal to undef: the C<defined> function (or method) can 59 be called or the C<//> (or C< err>) operator can be used.59 be called or the C<//> (or C<orelse>) operator can be used. 60 60 61 61 C<undef> is also considered to be false in a boolean context. -
docs/Perl6/Overview/File.pod
r15167 r17701 14 14 # if MODE left out it defaults to :r 15 15 16 my $fh = open "filename", :r errdie "Could not open file $!";16 my $fh = open "filename", :r orelse die "Could not open file $!"; 17 17 18 18 my $row = =$fh; # reading a line … … 27 27 =head2 Directories 28 28 29 my $dh = opendir "dirname" errdie "Could not open directory $!";29 my $dh = opendir "dirname" orelse die "Could not open directory $!"; 30 30 31 31 my @files = readdir($dh); -
docs/Perl6/Spec/Functions.pod
r17196 r17701 447 447 warning in doing so. There are two ways to determine if a 448 448 value equal to undef: the C<defined> function (or method) can 449 be called or the C<//> (or C< err>) operator can be used.449 be called or the C<//> (or C<orelse>) operator can be used. 450 450 451 451 C<undef> is also considered to be false in a boolean context. -
docs/notes/precompilation_cache.pod
r15167 r17701 122 122 die "no precompiled version found" unless $dir ~~ :d; 123 123 for $dir.readdir.sort:{numerically} -> $fn { 124 my ($pugsrev, $parserrev) = $fn ~~ /(\d+)-(\d+)/ errnext;124 my ($pugsrev, $parserrev) = $fn ~~ /(\d+)-(\d+)/ orelse next; 125 125 next if $XXX_handwaving($pugsrev, $parserrev); # against %?CONFIG<pugsrev> etc. 126 126 127 load_precompiled($fn) err{127 load_precompiled($fn) orelse { 128 128 $fn.rm; 129 129 die "error loading cached version: $!"; -
docs/notes/unicode_draft
r13280 r17701 215 215 216 216 # but you can handle it with 217 $x errdie "..."217 $x orelse die "..." 218 218 if $x { ... } -
docs/other/porting_howto
r16318 r17701 241 241 242 242 - open() 243 open my $fh, "<", $filename or die $!; -> my $fh = open($filename, :r) errdie $!;243 open my $fh, "<", $filename or die $!; -> my $fh = open($filename, :r) orelse die $!; 244 244 245 245 "<" -> :r -
docs/tutorial/ch04_basic_syntax.pod
r16700 r17701 449 449 keyword: 450 450 451 my $pi is constant= 3.14159;452 453 The C< constant> trait specifies that the value of the variable can't451 my $pi is readonly = 3.14159; 452 453 The C<readonly> trait specifies that the value of the variable can't 454 454 be changed. 455 455 … … 459 459 keyword: 460 460 461 $true_value = 0 but true;462 463 The C< true> property specifies that the value will evaluate as true in461 $true_value = 0 but True; 462 463 The C<True> property specifies that the value will evaluate as true in 464 464 a boolean context, no matter what the actual value is. This particular 465 property means the Perl 6 C< system> call can be checked with a simple465 property means the Perl 6 C<run> call can be checked with a simple 466 466 conditional. It still returns the same numeric values it always has (0 467 467 on success and a numeric error code on failure), but it flags the … … 488 488 more precisely than Perl 5, but keep in mind that explicit types are 489 489 completely optional. If you choose to use them, you'll gain some 490 benefits in optimization and interfacing between languages. The design491 of the type system isn't complete, but the basic groundwork is in 492 place.490 benefits in optimization and interfacing between languages. The biggest 491 benefit, however, is that types enable fine-grained control of multiple dispatch 492 when you want it, or course-grained contol when you don't care. 493 493 494 494 Perl 6 makes a distinction between the type of a value and the type of … … 508 508 509 509 my Int %hash; 510 511 The type of the keys may be declared in a pseudo-subscript. Since the 512 default key type is strings, the preceding declaration is actually short for: 513 514 my Int %hash{Str}; 515 516 To declare a hash that uses any object type for a key and always returns, 517 say, an icon object, say: 518 519 my Icon %hash{Any} 510 520 511 521 The I<variable> type specifies what kind of container the variable is. … … 698 708 @range = 3..Inf; # lazy 699 709 700 X<. (dot);... (infinite range);operator> 701 The C<...> operator is equivalent to C<..Inf>: 702 703 @range = 3...; 710 The C<*> token may be used instead of C<Inf>, which really only makes sense 711 for numeric types: 712 713 @range = 3..*; 714 @range = 'a'..*; 704 715 705 716 =head2 Comparison … … 739 750 are aliases to the same object. Each returns a true value if the 740 751 relation is true and a false value otherwise. The generic comparison 741 operators (C<E<lt>=E<gt>>, C< cmp>) return C<0> if the two arguments are752 operators (C<E<lt>=E<gt>>, C<leg>) return C<0> if the two arguments are 742 753 equal, C<1> if the first is greater, and C<-1> if the second is greater. 743 754 744 if ($age > 12){...}755 if $age > 12 {...} 745 756 746 757 Comparison operators can also be chained. Chained comparisons 747 758 evaluate each value in the chain only once. 748 759 749 if (24 < $age < 42){...} # 24 < $age and $age < 42760 if 24 < $age < 42 {...} # 24 < $age and $age < 42 750 761 751 762 =head2 Logical Operators … … 780 791 $splat = ($whale or $petunia); 781 792 782 X< err(test defined) operator>793 X<orelse (test defined) operator> 783 794 X</ (slash);// (test defined) operator> 784 795 A variant of the OR relation tests for definedness instead of truth. 785 It uses the C<//> operator and the low-precedence C< err> operator. The796 It uses the C<//> operator and the low-precedence C<orelse> operator. The 786 797 left-hand value is returned if it is defined, otherwise the right-hand 787 798 side is evaluated and its value returned: 788 799 789 800 $splat = $whale // $petunia; 790 $splat = ($whale err$petunia);801 $splat = ($whale orelse $petunia); 791 802 792 803 X<xor operator> … … 1095 1106 shortly. So while C<||> is a logical operation on two expressions: 1096 1107 1097 if ($value == 1) || ($value == 2){ ... }1108 if $value == 1 || $value == 2 { ... } 1098 1109 1099 1110 C<|> is the same logical relation between two values: … … 1113 1124 1114 1125 $junc = 1 | 2; 1115 if ($value == $junc){ ... }1126 if $value == $junc { ... } 1116 1127 1117 1128 Here, the variable C<$junc> is used in place of C<1 | 2>, and has … … 1233 1244 operators that's: 1234 1245 1235 if ($a != $c) && ($a != $d) && ($b != $c) && ($b != $d){ ... }1246 if $a != $c && $a != $d && $b != $c && $b != $d { ... } 1236 1247 1237 1248 If you want to get back a flat list of values from a junction, use the … … 1657 1668 Z<CHP-4-SECT-3.1.1> 1658 1669 1659 X<if (conditional);statement>1670 X<if conditional;statement> 1660 1671 The C<if> statement checks a condition and executes its associated 1661 1672 block only if that condition is true. The condition can be any -
docs/tutorial/ch07_grammars.pod
r16690 r17701 45 45 X<~ (tilde);~~ (smart match) operator> 46 46 47 if ($string ~~ m/\w+/){...}48 if ($string ~~ s/\w+/word/){...}49 if ($string ~~ /\w+/){...}47 if $string ~~ m/\w+/ {...} 48 if $string ~~ s/\w+/word/ {...} 49 if $string ~~ /\w+/ {...} 50 50 51 51 You can substitute other delimiters, like C<#...#>, C<[...]>, and 52 52 C<{...}> for the standard C</.../>, though C<?...?> and C<(...)> are 53 not valid delimiters. 54 55 if ($string ~~ s[\w+][word]) {...} 53 not valid delimiters: 54 55 $string ~~ s/\w+/word/ 56 57 Modifiers now come in front using I<adverb> syntax, so to do multiple 58 substitutions on the same string is: 59 60 $string ~~ s:g/\w+/word/ 61 62 Also, if you use brackets on the first part of a substitution, the second 63 part is specified as a pseudoassignment: 64 65 $string ~~ s[\w+] = 'word'; 66 67 This form also allows assignment operators, so if you want to add one to 68 all the number within a string, you can say: 69 70 $string ~~ s:g[\d+] += 1; 56 71 57 72 =head2 Deferred Matches -
examples/advocacy/motd-i.pl
r15167 r17701 14 14 my $dict = canonpath("$progdir/pugspraise"); 15 15 16 my $fh = open($dict) errdie $!;16 my $fh = open($dict) orelse die $!; 17 17 18 18 for =$fh->$line { -
examples/advocacy/motd.pl
r11293 r17701 12 12 my $limit = @*ARGS[0] // '2'; 13 13 my $dict = canonpath("$progdir/pugspraise"); 14 my $fh = open $dict errdie $!;14 my $fh = open $dict orelse die $!; 15 15 my @list = =$fh; 16 16 -
examples/cookbook/07file-access/07-01opening_file.pl
r11293 r17701 10 10 11 11 my $input = open($path, :r) 12 errdie "Could not open $path for reading $!\n";12 orelse die "Could not open $path for reading $!\n"; 13 13 14 14 my $filename = "test_file"; 15 15 my $output = open($filename, :w) 16 errdie "Could not open $filename for writing $!\n";16 orelse die "Could not open $filename for writing $!\n"; 17 17 18 18 … … 29 29 30 30 # Closing the file 31 # $input.close errdie $!;31 # $input.close orelse die $!; 32 32 # close($input); 33 33 -
examples/cookbook/07file-access/07-04making_perl_report_filenames_in_error_messages.pl
r11293 r17701 9 9 10 10 #my $fh = open($path) 11 # errdie "Could not open '$path' for reading: $!\n";11 # orelse die "Could not open '$path' for reading: $!\n"; 12 12 -
examples/games/hangman.pl
r12799 r17701 18 18 sub get_committer_list (Str $dict_file) returns List { 19 19 my @committers; 20 my $dict = open($dict_file) errdie "Couldn't open the AUTHORS file.\nYou must run this script from within the main pugs\ndirectory or within the examples/ sub-directory.";20 my $dict = open($dict_file) orelse die "Couldn't open the AUTHORS file.\nYou must run this script from within the main pugs\ndirectory or within the examples/ sub-directory."; 21 21 22 22 # Skip the intro text -
examples/games/hangman.pod
r6851 r17701 11 11 =head1 sub get_committer_list 12 12 13 C< err> is the low precedence form of C<//> (S03). C<//> is especially useful13 C<orelse> is the low precedence form of C<//> (S03). C<//> is especially useful 14 14 in its assignment form: 15 15 16 16 $x //= $y; 17 17 18 To summarize, C<||> and C<or> relate to truth, while C<//> and C< err> relate18 To summarize, C<||> and C<or> relate to truth, while C<//> and C<orelse> relate 19 19 to definedness. 20 20 -
examples/golf/tsanta.pl
r15167 r17701 24 24 25 25 sub golf_score (Str $script) returns Int { 26 my $fh = open($script) errdie("open '$script' failed: $!");26 my $fh = open($script) orelse die("open '$script' failed: $!"); 27 27 my $golf = 0; 28 28 my $dollar_dot = 0; # Note: $. aka $fh.linenum() not implemented yet … … 32 32 unless $dollar_dot==1 && $line.index("#!") == 0; 33 33 } 34 $fh.close() errdie("close '$script' failed: $!");34 $fh.close() orelse die("close '$script' failed: $!"); 35 35 return $golf; 36 36 } … … 43 43 44 44 sub build_file (Str $fname, Str $data) { 45 my $fh = open($fname, :w) errdie("open '$fname' failed: $!");46 $fh.print($data) errdie("print '$fname' failed: $!");47 $fh.close() errdie("close '$fname' failed: $!");45 my $fh = open($fname, :w) orelse die("open '$fname' failed: $!"); 46 $fh.print($data) orelse die("print '$fname' failed: $!"); 47 $fh.close() orelse die("close '$fname' failed: $!"); 48 48 } 49 49 … … 53 53 print("$label: running: '$cmd'..."); 54 54 # my $out = `$cmd`; 55 system($cmd) errdie("system '$cmd' failed: $!");55 system($cmd) orelse die("system '$cmd' failed: $!"); 56 56 # XXX: get return code. how? $!? (I think $? is obsolete in p6). 57 57 my $rc = 0; 58 my $out = slurp($outtmp) errdie("slurp '$outtmp' failed: $!");58 my $out = slurp($outtmp) orelse die("slurp '$outtmp' failed: $!"); 59 59 # my $rc = $? >> 8; 60 60 say("done (rc=$rc)"); -
examples/irclog2html.pl
r13342 r17701 72 72 73 73 # Pass I 74 my $fh = open @*ARGS[0] errdie "Couldn't open \"@*ARGS[0]\": $!\n";74 my $fh = open @*ARGS[0] orelse die "Couldn't open \"@*ARGS[0]\": $!\n"; 75 75 my $total = 0; 76 76 … … 99 99 100 100 # Pass I 101 $fh = open @*ARGS[0] errdie "Couldn't open \"@*ARGS[0]\": $!\n";101 $fh = open @*ARGS[0] orelse die "Couldn't open \"@*ARGS[0]\": $!\n"; 102 102 103 103 # This is the main coderef which processes a logline and returns HTML. -
examples/matrix.pl
r16636 r17701 69 69 70 70 gather { 71 for slurp '/usr/share/dict/words' :chomp errdie {71 for slurp '/usr/share/dict/words' :chomp orelse die { 72 72 next if /<-[a-z]>/; 73 73 /$re/ and take { word => $_, score => %scores{ .letters }.sum }; -
examples/naive_bayesian/naive_bayesian.pl
r15167 r17701 5 5 sub load_db returns Void { 6 6 return() unless "words.db.pl" ~~ :e; 7 my $db = open("words.db.pl") errdie "Cannot open the words.db.pl file: $!";7 my $db = open("words.db.pl") orelse die "Cannot open the words.db.pl file: $!"; 8 8 for (=$db) -> $_line { 9 9 my $line = $_line; … … 15 15 16 16 sub save_db returns Void { 17 my $db = open("words.db.pl", :w) errdie "Cannot open the words.db.pl file: $!";17 my $db = open("words.db.pl", :w) orelse die "Cannot open the words.db.pl file: $!"; 18 18 for (%words.kv) -> $key, $value { 19 19 $db.say($key ~ "\t" ~ $value); … … 24 24 sub parse_file (Str $file) returns Hash { 25 25 my %words_in_file; 26 my $fh = open("$file") errdie "Cannot open the '$file' file: $!";26 my $fh = open("$file") orelse die "Cannot open the '$file' file: $!"; 27 27 for (=$fh) -> $_line { 28 28 my $line = $_line; -
examples/network/hangmanbot.pl
r12807 r17701 20 20 sub get_committer_list(Str $dict_file) returns List { 21 21 my @committers; 22 my $dict = open($dict_file) err22 my $dict = open($dict_file) orelse 23 23 die "Couldn't open \"$dict_file\": $!\n"; 24 24 -
examples/p6explain/p6explain
r11293 r17701 6 6 7 7 # Parsing the dat 8 my $fh = open $dat errdie "Couldn't open \"$dat\" for reading: $!\n";8 my $fh = open $dat orelse die "Couldn't open \"$dat\" for reading: $!\n"; 9 9 for =$fh { 10 10 state $cur_entry; -
examples/password-manager.p6
r16177 r17701 90 90 91 91 sub xclip(Str $s -->) { 92 my IO $xclip = Pipe.to: 'xclip' errabort 'No xclip - use .p';92 my IO $xclip = Pipe.to: 'xclip' orelse abort 'No xclip - use .p'; 93 93 $xclip.print: $s; 94 94 $xclip.close; … … 98 98 my Str $pw = %pw{$s}<pass> // 99 99 first Str, (%pw{$_}<pass> if /$s/ for %pw.keys) 100 errabort "Couldn't find account $s";100 orelse abort "Couldn't find account $s"; 101 101 xclip $pw; 102 102 cmt if $changed; … … 117 117 118 118 sub cmt(-->) { 119 unlink 'pwd.gpg.old' errabort "Couldn't unlink: $!";120 rename 'pwd.gpg', 'pwd.gpg.old' errabort "Couldn't rename: $!";119 unlink 'pwd.gpg.old' orelse abort "Couldn't unlink: $!"; 120 rename 'pwd.gpg', 'pwd.gpg.old' orelse abort "Couldn't rename: $!"; 121 121 my IO $pwd = Pipe.to: 'gpg --symmetric --force-mdc --cipher-algo AES256 --output pwd.gpg' 122 errabort "Couldn't encrypt: $!";122 orelse abort "Couldn't encrypt: $!"; 123 123 for %pw.keys -> $k { $pwd.say: $k, "\t", %pw{$k}<pass user>.join("\t") } 124 124 if $pwd.close { … … 168 168 %*ENV<PATH> = '/bin:/usr/bin:/usr/bin/X11'; 169 169 umask 0o77; 170 chdir "$+HOME/pw" errdie "Couldn't cd: $!";171 my IO $pwd = Pipe.from: 'gpg --output - --decrypt pwd.gpg' errdie "Couldn't decrypt: $!";170 chdir "$+HOME/pw" orelse die "Couldn't cd: $!"; 171 my IO $pwd = Pipe.from: 'gpg --output - --decrypt pwd.gpg' orelse die "Couldn't decrypt: $!"; 172 172 for =$pwd { 173 173 /<pwent>/ or die 'Malformed line ', $pwd.linenum, ": $_\n"; -
examples/perl5/cpan-upload.pl
r15167 r17701 230 230 #------------------------------------------------------------------- 231 231 _debug(" creating instance of LWP::UserAgent\n"); 232 $agent = LWP::UserAgent.new() errdie "Failed to create UserAgent: $!\n";232 $agent = LWP::UserAgent.new() orelse die "Failed to create UserAgent: $!\n"; 233 233 $agent.agent("$PROGRAM/$VERSION"); 234 234 $agent.from($config.mailto); -
examples/perldoc.pl
r15167 r17701 46 46 sub display_pod { 47 47 my ($podfile) = @_; 48 my $fh = open $podfile errdie "Could not open '$podfile'\n";48 my $fh = open $podfile orelse die "Could not open '$podfile'\n"; 49 49 for =$fh -> $line { 50 50 say $line; … … 62 62 for list_files(dirname($PROGRAM_NAME)) -> $podfile { 63 63 say "Processing '$podfile'"; 64 my $fh = open $podfile errdie "Could not open '$podfile'\n";64 my $fh = open $podfile orelse die "Could not open '$podfile'\n"; 65 65 my $row = 0; 66 66 my $section; … … 86 86 sub list_files ($dir, $full) {
