Skip to content

Commit 70b0ca3

Browse files
committed
Updates to latest design concepts for GLR.
Added a status summary at the top of the document. Reintroduced Parcel as an immutable List type. Other small cleanups.
1 parent 64b65ba commit 70b0ca3

File tree

1 file changed

+57
-38
lines changed

1 file changed

+57
-38
lines changed

S07-glr-draft.pod

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,55 @@ that must be addressed.
2525
This document describes the post-GLR design for lists in Perl 6.
2626
Some portions may contain a fair bit of guesswork.
2727

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 .[]
2939

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.
3342

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
3748

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
4050

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.
4354

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.
4859

49-
() # empty List
60+
() # empty Parcel
5061
(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.
5377

5478
=head2 The C<Array> type
5579

@@ -62,15 +86,15 @@ array.
6286
(Update 2015-06-22: Flattening behavior may be implemented internally
6387
via a C<:flat> flag on C<Slip> objects, described below.)
6488

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".
7094

7195
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>.
7498

7599
Flattening occurs when assigning or initializing an array:
76100

@@ -88,7 +112,9 @@ Flattening also occurs using the C<flat> contextualizer:
88112
Slurpy array parameters declared with a single C<*> marker lazily
89113
flatten the arguments into the array.
90114

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]
92118

93119
Conjecture: An array constructor preceded by a colon flattens its
94120
interior contents. Array constructors without the colon do not flatten
@@ -107,7 +133,7 @@ context, even if the object is C<Iterable>.
107133
my $s = @a;
108134
my @c = 1, 2, $s; # @c has three elements
109135

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,
111137
but the presence of the scalar container prevents C<$s> from being
112138
flattened into C<@c>. The C<.list> or C<.flat> method may be used
113139
to restore the flattening behavior:
@@ -151,10 +177,10 @@ or known infinite.)
151177
=head2 The C<Slip> type
152178

153179
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>
155181
is encountered. In most cases C<Slip> objects are expected to
156182
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.
158184

159185
C<Slip> can be used to interpolate values into a list in a way
160186
that doesn't flatten or itemize the values.
@@ -188,14 +214,7 @@ free to add questions or comments below, including references to relevant
188214

189215
=item *
190216

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
199218
disappearing. We really need two types here; one (base) type that
200219
represents immutable lists, and another type that represents mutable
201220
lists. The C<< infix:<,> >> operator would produce the immutable type.
@@ -252,7 +271,7 @@ instead of a class.
252271
=item *
253272

254273
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>.
256275

257276
Question: Is the special "least surprise" eager behavior of
258277
for-as-a-last-(bare)-statement preserved?

0 commit comments

Comments
 (0)