- Timestamp:
- 09/06/07 19:43:34 (16 months ago)
- Location:
- docs
- Files:
-
- 8 modified
-
Perl6/API/Scalar.pod (modified) (1 diff)
-
Perl6/Overview/File.pod (modified) (2 diffs)
-
Perl6/Spec/Functions.pod (modified) (1 diff)
-
notes/precompilation_cache.pod (modified) (1 diff)
-
notes/unicode_draft (modified) (1 diff)
-
other/porting_howto (modified) (1 diff)
-
tutorial/ch04_basic_syntax.pod (modified) (11 diffs)
-
tutorial/ch07_grammars.pod (modified) (1 diff)
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
