Revision 26292

Date:
2009/04/19 18:19:50
Author:
lwall
Revision Log:
Kill prefix:<=> very, very dead.
Files:

Legend:

 
Added
 
Removed
 
Modified
  • docs/Perl6/Spec/S02-bits.pod

     
    12 12
    13 13 Maintainer: Larry Wall <larry@wall.org>
    14 14 Date: 10 Aug 2004
    15 Last Modified: 10 Apr 2009
    15 Last Modified: 19 Apr 2009
    16 16 Number: 2
    17 Version: 163
    17 Version: 164
    18 18
    19 19 This document summarizes Apocalypse 2, which covers small-scale
    20 20 lexical items and typological issues. (These Synopses also contain
     
    2502 2502 you should use C<< ['a'] >> for clarity as well as correctness.
    2503 2503
    2504 2504 The degenerate case C<< <> >> is disallowed as a probable attempt to
    2505 do IO in the style of Perl 5; that is now written C<< =<> >>. (C<<
    2505 do IO in the style of Perl 5; that is now written C<lines()>. (C<<
    2506 2506 <STDIN> >> is also disallowed.) Empty lists are better written with
    2507 2507 C<()> or C<Nil> in any case because C<< <> >> will often be misread
    2508 2508 as meaning C<('')>. (Likewise the subscript form C<< %foo<> >>
     
    3540 3540 =item *
    3541 3541
    3542 3542 To force non-lazy list flattening, use the C<eager> list operator.
    3543 Don't use it on an infinite list unless you have a machine with
    3544 infinite memory, and are willing to wait a long time. To expand an
    3545 iterator object to completion, iterate it with C<< prefix:<=> >>
    3546 inside an eager list:
    3543 List assignment is also implicitly eager.
    3547 3544
    3548 @lines = eager =$filehandle; # read all remaining lines
    3545 eager $filehandle.lines; # read all remaining lines
    3549 3546
    3550 3547 By contrast,
    3551 3548
    3552 @lines = =$filehandle;
    3549 $filehandle.lines;
    3553 3550
    3554 3551 makes no guarantee about how many lines ahead the iterator has read.
    3555 Iterators appending to a list are allowed to process in batches, even
    3552 Iterators feeding a list are allowed to process in batches, even
    3556 3553 when stored within an array. The array knows that it is extensible,
    3557 3554 and calls the iterator as it needs more elements. (Counting the elements
    3558 3555 in the array will also force eager completion.)
     
    3651 3648
    3652 3649 you now write
    3653 3650
    3654 for =$handle {...}
    3651 for @$handle {...}
    3655 3652
    3656 As a unary prefix operator, you may also apply adverbs to C<=>:
    3657
    3658 for =$handle :prompt('$ ') { say $_ + 1 }
    3659
    3660 3653 or
    3661 3654
    3662 for =($handle):prompt('$ ') { say $_ + 1 }
    3655 for $handle.lines {...}
    3663 3656
    3664 or you may even write it in its functional form, passing the adverbs
    3665 as ordinary named arguments.
    3666
    3667 for prefix:<=>($handle, :prompt('$ ')) { say $_ + 1 }
    3668
    3669 3657 =back
    3670 3658
    3671 3659 =head1 Properties
  • docs/Perl6/Spec/S03-operators.pod

     
    12 12
    13 13 Maintainer: Larry Wall <larry@wall.org>
    14 14 Date: 8 Mar 2004
    15 Last Modified: 10 Apr 2009
    15 Last Modified: 19 Apr 2009
    16 16 Number: 3
    17 Version: 162
    17 Version: 163
    18 18
    19 19 =head1 Overview
    20 20
     
    33 33 L Method postfix .meth .+ .? .* .() .[] .{} .<> .«» .:: .= .^ .:
    34 34 N Autoincrement ++ --
    35 35 R Exponentiation **
    36 L Symbolic unary ! + - ~ ? | +^ ~^ ?^ ^ =
    36 L Symbolic unary ! + - ~ ? | +^ ~^ ?^ ^
    37 37 L Multiplicative * / % +& +< +> ~& ~< ~> ?& div mod
    38 38 L Additive + - +| +^ ~| ~^ ?| ?^
    39 39 L Replication x xx
     
    678 678 Constructs a range of C<0 ..^ $limit> or locates a metaclass as a shortcut
    679 679 for C<$limit.HOW>. See L</Range semantics>.
    680 680
    681 =item *
    682
    683 C<< prefix:<=> >>, iterate iterator
    684
    685 =$iterator
    686
    687 Unary C<=> reads lines from a filehandle or filename, or
    688 iterates an iterator, or in general causes a scalar to explode its guts
    689 when it would otherwise not. How it does that is context sensitive.
    690 For instance, C<=$iterator> is item/list context sensitive and will
    691 produce one value in item context but many values in list context.
    692 The production of values is abstract here, so a lazy list merely
    693 remembers that it should iterate the iterator to completion upon
    694 demand. Use an eager list to force completion.
    695
    696 Use C<@$iterator> to produce a list of all the values even in item
    697 context, and C<$$iterator> to produce a single value even
    698 in list context. On the other hand, C<=$capture> produces all
    699 parts of the capture that makes sense in the current list context,
    700 depending on what controls that list context. [Conjecture: the
    701 previous sentence is non-sensical.]
    702
    703 681 =back
    704 682
    705 683 =head2 Multiplicative precedence
  • docs/Perl6/Spec/S04-control.pod

     
    12 12
    13 13 Maintainer: Larry Wall <larry@wall.org>
    14 14 Date: 19 Aug 2004
    15 Last Modified: 17 Apr 2009
    15 Last Modified: 19 Apr 2009
    16 16 Number: 4
    17 Version: 75
    17 Version: 76
    18 18
    19 19 This document summarizes Apocalypse 4, which covers the block and
    20 20 statement syntax of Perl.
     
    435 435
    436 436 while (my $line = <STDIN>) {...}
    437 437
    438 in Perl 6 you should use a C<for> (plus a unary C<=> "iterate the
    439 iterator" operator) instead:
    438 in Perl 6 you should use a C<for> instead:
    440 439
    441 for =$*IN -> $line {...}
    440 for $*IN.lines -> $line {...}
    442 441
    443 442 This has the added benefit of limiting the scope of the C<$line>
    444 443 parameter to the block it's bound to. (The C<while>'s declaration of
    445 444 C<$line> continues to be visible past the end of the block. Remember,
    446 445 no implicit block scopes.) It is also possible to write
    447 446
    448 while =$*IN -> $line {...}
    447 while $*IN.get -> $line {...}
    449 448
    449 However, this is likely to fail on autochomped filehandles, so use
    450 the C<for> loop instead.
    451
    450 452 Note also that Perl 5's special rule causing
    451 453
    452 454 while (<>) {...}
     
    454 456 to automatically assign to C<$_> is not carried over to Perl 6. That
    455 457 should now be written:
    456 458
    457 for =<> {...}
    459 for lines() {...}
    458 460
    459 461 which is short for
    460 462
    461 for =$*ARGFILES {...}
    463 for lines($*ARGFILES) {...}
    462 464
    463 465 Arguments bound to the formal parameters of a pointy block are by
    464 466 default readonly within the block. You can declare a parameter
  • docs/Perl6/Spec/S05-regex.pod

     
    14 14 Maintainer: Patrick Michaud <pmichaud@pobox.com> and
    15 15 Larry Wall <larry@wall.org>
    16 16 Date: 24 Jun 2002
    17 Last Modified: 22 Mar 2009
    17 Last Modified: 19 Mar 2009
    18 18 Number: 5
    19 Version: 94
    19 Version: 95
    20 20
    21 21 This document summarizes Apocalypse 5, which is about the new regex
    22 22 syntax. We now try to call them I<regex> rather than "regular
     
    4041 4041 Anything that can be tied to a string can be matched against a
    4042 4042 regex. This feature is particularly useful with input streams:
    4043 4043
    4044 my $stream := cat =$fh; # tie scalar to filehandle
    4044 my $stream := cat $fh.lines; # tie scalar to filehandle
    4045 4045
    4046 4046 # and later...
    4047 4047
  • docs/Perl6/Spec/S07-iterators.pod

     
    10 10 Contributions: Tim Nelson <wayland@wayland.id.au>
    11 11 Daniel Ruoso <daniel@ruoso.com>
    12 12 Date: 27 Nov 2008
    13 Last Modified: 28 Dec 2008
    14 Version: 3
    13 Last Modified: 19 Apr 2008
    14 Version: 4
    15 15
    16 16 =head1 Laziness and Eagerness
    17 17
     
    193 193
    194 194 You can later do:
    195 195
    196 my $item = =$it;
    196 my $item = $it.get;
    197 my @items = @$it;
    197 198
    198 Or if the double '=' bothers you in front:
    199
    200 my $item2 = $it.:<=>;
    201
    202 (XXX TODO: decide whether the item iterator flattens, document)
    203
    204 199 (XXX TODO: effect of type constraints of $it -- maybe to control flattening? )
    205 200
    206 201 (XXX TODO:
    207 202
    208 203 What's this do?
    209 204
    210 my $it <== @a; my $it2 <== $it; my $it3 <== $it; =$it2; =$it3;
    205 my $it <== @a; my $it2 <== $it; my $it3 <== $it; get $it2; get $it3;
    211 206
    212 207 ...allow tag team suckling?
    213 208
     
    337 332 my @a = (1);
    338 333 my $it;
    339 334 $it <== my_coro() <== while 1 { shift(@a) };
    340 say "First result: " ~ =$it;
    335 say "First result: " ~ get $it;
    341 336 @a.push("Hello World");
    342 say "Second result: " ~ =$it;
    337 say "Second result: " ~ get $it;
    343 338 @a.push(500);
    344 say "Third result: " ~ =$it;
    339 say "Third result: " ~ get $it;
    345 340
    346 341 ...if you want to pass multiple parameters on each call, you can
    347 342 use a slice slurpy instead, to pass a C<Capture>.
     
    358 353 }
    359 354 method corocall($message) {
    360 355 @!data.push($message);
    361 =$!it;
    356 get $!it;
    362 357 }
    363 358 }
    364 359 my $c = my_sub2coro.new(coro => &my_coro);
  • docs/Perl6/Spec/S09-data.pod

     
    360 360
    361 361 my @@x;
    362 362 @@x <== %hash.keys.grep: {/^\d+$/};
    363 @@x <== =<>;
    363 @@x <== lines;
    364 364 @@x <== 1..*;
    365 365 @@x <== gather { loop { take 100.rand } };
    366 366
     
    372 372
    373 373 my @x;
    374 374 @x <== %hash.keys.grep: {/^\d+$/};
    375 @x <== =<>;
    375 @x <== lines;
    376 376 @x <== 1..*;
    377 377 @x <== gather { loop { take 100.rand } };
    378 378
  • docs/Perl6/Spec/S16-io.pod

     
    12 12 Tim Nelson <wayland@wayland.id.au>
    13 13 Daniel Ruoso <daniel@ruoso.com>
    14 14 Date: 12 Sep 2006
    15 Last Modified: 23 Feb 2009
    16 Version: 21
    15 Last Modified: 19 Apr 2009
    16 Version: 22
    17 17
    18 18 This is a draft document. Many of these functions will work as in Perl
    19 19 5, except we're trying to rationalize everything into roles. For
     
    41 41
    42 42 When no explicit filehandle is used, the standard IO operators are
    43 43 defined in terms of the contextual variables. So the C<print> function
    44 prints to C<$*OUT>, while C<warn> warns to C<$*ERR>. The C<< =<> >>
    45 term inputs from C<$*IN>. So any given dynamic scope (interpreter,
    44 prints to C<$*OUT>, while C<warn> warns to C<$*ERR>. The C<< lines() >>
    45 term inputs from C<$*ARGFILES> which defaults to C<$*IN> in the absence of any
    46 filenames. So any given dynamic scope (interpreter,
    46 47 thread, function or method call) may redefine the current meaning of
    47 48 any of those filehandles within the dynamic scope of itself and of
    48 49 its called routines.
  • docs/Perl6/Spec/S28-special-names.pod

     
    10 10 Lyle Hopkins <webmaster@cosmicperl.com>
    11 11 Date: 23 Feb 2009, created by Tim Nelson from miscellaneous documents lying around
    12 12 Last Modified: 19 Apr 2009
    13 Version: 5
    13 Version: 6
    14 14
    15 15 =head1 Special Variables
    16 16
     
    201 201 $^W $*WARNINGS (if any dynamic control needed)
    202 202 ${^WARNING_BITS} $?WARNINGS
    203 203 $^X $*EXECUTABLE_NAME ...or some such
    204 ARGV $*ARGS Note the P6 idiom for this handle:
    205 for =$*ARGS {
    204 ARGV $*ARGFILE Note the P6 idiom for this handle:
    205 for lines() {
    206 206 # each time through loop
    207 207 # proc a line from files named in ARGS
    208 208 }
  • docs/Perl6/Spec/S32-setting-library/Str.pod

     
    349 349
    350 350 =item comb
    351 351
    352 our List multi comb ( Regex $matcher = /\S+/, Str $input, Int $limit = * )
    352 our List multi comb ( Regex $matcher, Str $input, Int $limit = * )
    353 353 our List multi method comb ( Str $input: Regex $matcher = /\S+/, Int $limit = * )
    354 354
    355 355 The C<comb> function looks through a string for the interesting bits,
     
    454 454
    455 455 sprintf "%d%C is %d digits long",
    456 456 $num,
    457 sub($s,@args is rw) {@args[2]=$s.elems},
    457 sub ($s, @args is rw) { @args[2] = $s.elems },
    458 458 0;
    459 459
    460 460 The special directive, C<%n> does not work in Perl 6 because of the