Revision 26302

Date:
2009/04/20 08:30:10
Author:
lwall
Revision Log:
[S32] add limit to lines
[S07] refine get/iterator semantics; fix typos
Files:

Legend:

 
Added
 
Removed
 
Modified
  • docs/Perl6/Spec/S07-iterators.pod

     
    6 6
    7 7 =head1 Version
    8 8
    9 Maintainer: ???
    9 Maintainer: *
    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: 19 Apr 2008
    14 Version: 4
    13 Last Modified: 20 Apr 2008
    14 Version: 5
    15 15
    16 16 =head1 Laziness and Eagerness
    17 17
     
    32 32 =item Strictly Lazy
    33 33
    34 34 Does not evaluate anything unless explictly required by the user,
    35 including not traversing non-lazy objects.
    35 including not traversing non-lazy objects. This behavior is generally
    36 available only by pragma or by explicit programming with non-lazy
    37 primitives.
    36 38
    37 39 =item Mostly Lazy
    38 40
    39 41 Try to obtain available items without causing eager evaluation of
    40 other lazy objects.
    42 other lazy objects. However, the implementation is allowed to do batching
    43 for efficiency.
    41 44
    42 45 =item Mostly Eager
    43 46
     
    47 50 =item Strictly Eager
    48 51
    49 52 Obtain all items, fail in data structures known to be infinite.
    53 This behavior is generally available only by pragma or by explicit
    54 programming primitives.
    50 55
    51 56 =back
    52 57
    53 It's important to realize that the responsability of determining the
    54 level of lazyness/eagerness in each operation is external to each lazy
    58 It's important to realize that the responsibility of determining the
    59 level of laziness/eagerness in each operation is external to each lazy
    55 60 object, the runtime, depending on which operation is being performed,
    56 is going to assume the level of lazyness and perform the needed
    61 is going to assume the level of laziness and perform the needed
    57 62 operations to apply that level.
    58 63
    59 =head2 The lazyness level of some common operations
    64 =head2 The laziness level of some common operations
    60 65
    61 66 =over
    62 67
     
    91 96 =back
    92 97
    93 98 But it's important to notice that eagerness takes precedence over
    94 lazyness, meaning that
    99 laziness, meaning that
    95 100
    96 101 my @a = grep { ... } <== map { ... } <== grep { ... } <== 1, 2, 3
    97 102
     
    111 116 my @b <== map { ... }, @c;
    112 117 my @a = grep { ... }, @b;
    113 118
    114 provides the same lazyness level of the first example.
    119 provides the same laziness level of the first example.
    115 120
    116 121 =head1 The Iterator Role
    117 122
     
    142 147
    143 148 =head2 method get {...}
    144 149
    145 Returns the items for that iteration. The grouping of elements
    150 Returns the next item for that iteration. The grouping of elements
    146 151 returned in each iteration is visible if this iterator is being used
    147 152 to build a slice. While building a List, the items will be flattened.
    148 153
    149 When it runs out of items, it will throw an OutOfItemsException.
    154 When it runs out of items, it will return C<Nil>.
    150 155
    151 156 =head1 The Iterator::PushBack Role
    152 157
  • docs/Perl6/Spec/S32-setting-library/IO.pod

     
    17 17 Daniel Ruoso <daniel@ruoso.com>
    18 18 Lyle Hopkins <webmaster@cosmicperl.com>
    19 19 Date: 19 Feb 2009 extracted from S29-functions.pod; added stuff from S16-IO later
    20 Last Modified: 13 Apr 2009
    21 Version: 5
    20 Last Modified: 20 Apr 2009
    21 Version: 6
    22 22
    23 23 The document is a draft.
    24 24
     
    830 830 =item lines
    831 831
    832 832 method lines ($handle:
    833 Any $limit = *,
    833 834 Bool :$bin = False,
    834 835 Str :$enc = "Unicode",
    835 836 Any :$nl = "\n",
     
    838 839 ) is export
    839 840
    840 841 multi lines (Str $filename,
    842 Any $limit = *,
    841 843 Bool :$bin = False,
    842 844 Str :$enc = "Unicode",
    843 845 Any :$nl = "\n",
     
    845 847 --> List
    846 848 )
    847 849
    848 Returns all the lines of a file as a C<List> regardless of context.
    850 Returns some or all the lines of a file as a C<List> regardless of context.
    849 851 See also C<slurp>. Note that lists are lazy by default, but you
    850 can always ask for C<eager lines>.
    852 can always ask for C<eager lines>. Note that the limit semantics cannot be
    853 duplicated by subscripting, since
    851 854
    855 $fh.lines[^5]
    856
    857 reads all the lines before the subscript gives you the first five,
    858 whereas
    859
    860 $fh.lines(5)
    861
    862 reads only five lines from the handle. Note that
    863
    864 $fh.lines(1)
    865
    866 is equivalent to
    867
    868 $fh.get
    869
    870 If fewer lines are available than the limit, it is not an error;
    871 you just get the number of lines available.
    872
    852 873 =item slurp
    853 874
    854 875 method slurp ($handle: