@@ -25,31 +25,55 @@ that must be addressed.
25
25
This document describes the post-GLR design for lists in Perl 6.
26
26
Some portions may contain a fair bit of guesswork.
27
27
28
- =head2 The C<List> type
28
+ =head2 Brief status summary
29
+
30
+ Here's a brief status of major design components:
31
+
32
+ Parcel An immutable sequence of elements, created by infix:<,>
33
+ List A mutable sequence of elements (e.g., push, pop)
34
+ Array A List in which all elements are in scalar containers
35
+ Slip Elements to be "inlined" with an outer list
36
+ Seq Elements produced by generators such as lines(), map(), gather/take
37
+ Iterable Things that may flatten in context
38
+ Positional Binds to @-variables and support .[]
29
39
30
- The C<List> class is the base class for dealing with other types of
31
- lists, including C<Array>. To the programmer, a C<List> is a potentially
32
- lazy and infinite sequence of elements.
40
+ Slip implements most flattening, itemizing, and laziness behaviors.
41
+ Seq is not Positional, thus cannot be bound to array variables.
33
42
34
- Lists may be mutable, in that one can manipulate the sequence via
35
- operations such as C<push>, C<pop>, C<shift>, C<unshift>, C<splice>,
36
- etc. A C<List>'s elements may be either mutable or immutable.
43
+ Known flattening contexts:
44
+ Array initialization and assignment
45
+ Using the 'flat' contextualizer
46
+ Inside of .[]
47
+ Arguments to list operators (X/Z) no longer flatten
37
48
38
- C<List> objects are C<Positional>, meaning they can be bound to
39
- array variables and support the postfix C<.[]> operator.
49
+ =head2 Parcel
40
50
41
- Lists are also lazy, in that the elements of a C<List> may
42
- come from generator functions that produce elements on demand.
51
+ The C<Parcel> class is the base class for dealing with most types of
52
+ lists, including C<List> and C<Array>. To the programmer, a C<Parcel>
53
+ is a lazy, immutable, and potentially infinite sequence of elements.
43
54
44
- The comma operator (C<< infix:<,> >>) creates (possibly immutable)
45
- C<List> objects. The elements of such a list may be mutable or
46
- immutable. Except for empty lists , parentheses are not used in the
47
- creation of C<List > objects.
55
+ Parcels are created using the comma operator (C<< infix:<,> >>).
56
+ The elements within a C<Parcel> may be either mutable or immutable.
57
+ Except for empty parcels , parentheses are not used in the creation
58
+ of C<Parcel > objects.
48
59
49
- () # empty List
60
+ () # empty Parcel
50
61
(1) # an Int
51
- (1,2) # a List with two Ints
52
- (1,) # a List with one Int
62
+ (1,2) # a Parcel with two Ints
63
+ (1,) # a Parcel with one Int
64
+
65
+ C<Parcel> objects are C<Positional>, meaning they can be bound to
66
+ array variables and they support the postcircumfix C<.[]> operator.
67
+
68
+ Parcels are lazy, in that the elements of the parcel may come from
69
+ generators that produce elements on demand.
70
+
71
+ =head2 The C<List> type
72
+
73
+ A C<List> is a C<Parcel> that is mutable, in that one can manipulate
74
+ the sequence via operations such as C<push>, C<pop>, C<shift>,
75
+ C<unshift>, C<splice>, etc. As with a C<Parcel>, the elements of
76
+ a list may be either mutable or immutable.
53
77
54
78
=head2 The C<Array> type
55
79
@@ -62,15 +86,15 @@ array.
62
86
(Update 2015-06-22: Flattening behavior may be implemented internally
63
87
via a C<:flat> flag on C<Slip> objects, described below.)
64
88
65
- C<List> objects can have other container objects as elements.
66
- In some contexts we want to interpolate the values of container
67
- objects into the surrounding C<List> , while in other contexts we
68
- want any subcontainers to be preserved . Such interpolation is
69
- known as "flattening".
89
+ Parcels and other lists can have other container objects as elements.
90
+ In some contexts we want to preserve the structure of (sub)containers
91
+ within a list , while in other contexts we want to interpolate the
92
+ subcontainer elements into the surrounding list . Such interpolation
93
+ is known as "flattening".
70
94
71
95
The C<Iterable> type is performed by container and generator objects
72
- that will interpolate their values in flattening contexts. C<List >,
73
- C<Array>, and C<Range> objects are C<Iterable>.
96
+ that will interpolate their values in flattening contexts. C<Parcel >,
97
+ C<List>, C< Array>, and C<Range> objects are C<Iterable>.
74
98
75
99
Flattening occurs when assigning or initializing an array:
76
100
@@ -88,7 +112,9 @@ Flattening also occurs using the C<flat> contextualizer:
88
112
Slurpy array parameters declared with a single C<*> marker lazily
89
113
flatten the arguments into the array.
90
114
91
- In the pre-GLR, list operators such as reduce, cross, and zip flatten their arguments... not sure if that carries over to post-GLR.
115
+ Flattening occurs inside of C<.[ ]> brackets:
116
+
117
+ say @a[2..5,10]; # same as @a[2,3,4,5,10]
92
118
93
119
Conjecture: An array constructor preceded by a colon flattens its
94
120
interior contents. Array constructors without the colon do not flatten
@@ -107,7 +133,7 @@ context, even if the object is C<Iterable>.
107
133
my $s = @a;
108
134
my @c = 1, 2, $s; # @c has three elements
109
135
110
- Here, both C<$s> and C<@a> refer to the same underlying C<Array> object,
136
+ Here, C<$s> and C<@a> both refer to the same underlying C<Array> object,
111
137
but the presence of the scalar container prevents C<$s> from being
112
138
flattened into C<@c>. The C<.list> or C<.flat> method may be used
113
139
to restore the flattening behavior:
@@ -151,10 +177,10 @@ or known infinite.)
151
177
=head2 The C<Slip> type
152
178
153
179
The C<Slip> type is used for lists of values to be immediately
154
- "slipped" into any outer containing list as soon as the C<Slip>
180
+ "slipped" into any outer containing list when the C<Slip>
155
181
is encountered. In most cases C<Slip> objects are expected to
156
182
be "ephemeral" (or "slippery") in the sense that they tend to
157
- disappear before they can be accessed.
183
+ disappear once they are encountered or accessed.
158
184
159
185
C<Slip> can be used to interpolate values into a list in a way
160
186
that doesn't flatten or itemize the values.
@@ -188,14 +214,7 @@ free to add questions or comments below, including references to relevant
188
214
189
215
=item *
190
216
191
- The C<Parcel> type is going away (yay!). C<< infix:<,> >> will
192
- directly produce C<List> objects. This changes the way that nested
193
- parenthesized comma lists react to things like C<.elems> and C<.[]>.
194
-
195
- (1, (2, 3)).elems # (pre-GLR) 3; (post-GLR) 2
196
- (1, 2, 3..7).elems # (pre-GLR) 7; (post-GLR) 3
197
-
198
- Update 2015-06-22: Okay, I'm no longer certain that C<Parcel> is
217
+ Update 2015-06-22: I'm no longer certain that C<Parcel> is
199
218
disappearing. We really need two types here; one (base) type that
200
219
represents immutable lists, and another type that represents mutable
201
220
lists. The C<< infix:<,> >> operator would produce the immutable type.
@@ -252,7 +271,7 @@ instead of a class.
252
271
=item *
253
272
254
273
Looping constructs ( C<while>, C<for>, C<until>, C<loop> ) will be able
255
- to lazily return lists , as described in C<S04>.
274
+ to lazily return generators , as described in C<S04>.
256
275
257
276
Question: Is the special "least surprise" eager behavior of
258
277
for-as-a-last-(bare)-statement preserved?
0 commit comments