Skip to content

Commit befa434

Browse files
committed
Describe value & symbol sequences; minor fixes
1 parent 660de2b commit befa434

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

articles/ctarguments.dd

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $(HEADERNAV_TOC)
1616
internals, but don't get confused - they don't have much in common with tuples that
1717
commonly exist in other languages. Sequences of values of different types that can be
1818
returned from functions are provided by $(PHOBOS typecons, .Tuple, std.typecons.Tuple).
19-
Using term "tuple" to mean compile-time sequences is discouraged to avoid confusion, and if encountered
19+
Using the term "tuple" to mean compile-time sequences is discouraged to avoid confusion, and if encountered
2020
should result in a $(LINK2 https://issues.dlang.org, documentation bug report).
2121
)
2222

@@ -115,7 +115,7 @@ $(H2 $(LNAME2 available-operations, Available operations))
115115

116116
$(P D's $(LINK2 spec/statement.html#ForeachStatement, foreach statement) has special
117117
semantics when iterating over compile-time sequences. It repeats the body of the loop
118-
for each of the sequence elements, with the loop iteration "variable" becoming an alias
118+
for each of the sequence elements, with the loop iteration symbol being an alias
119119
for each compile-time sequence element in turn.
120120
)
121121

@@ -134,7 +134,6 @@ $(H2 $(LNAME2 available-operations, Available operations))
134134
}
135135

136136
/* Prints:
137-
138137
int
139138
string
140139
void()
@@ -172,7 +171,7 @@ $(H2 $(LNAME2 homogenous-sequences, Homogenous sequences))
172171

173172
$(P An $(ALOCAL AliasSeq, AliasSeq) that consists of only type or value elements are
174173
commonly called "type sequences" or "value sequences" respectively. The concept of
175-
a "symbol sequence" is rarely mentioned explicitly but fits the same pattern.
174+
a "symbol sequence" is used less frequently but fits the same pattern.
176175
)
177176

178177
$(H3 $(LNAME2 type-seq, Type sequences))
@@ -208,8 +207,8 @@ $(H4 $(LNAME2 type-seq-instantiation, Type sequence instantiation))
208207
alias variables = AliasSeq!(__var1, __var2, __var3);
209208
---
210209

211-
$(P So a type sequence instance acts as a symbol sequence that only aliases
212-
variables.)
210+
$(P So a type sequence instance is a kind of symbol sequence that only aliases
211+
variables, known as an $(I lvalue sequence).)
213212

214213
$(P $(DDSUBLINK spec/template, variadic-templates, Variadic template functions)
215214
use a type sequence instance for a function parameter:)
@@ -229,20 +228,39 @@ $(H4 $(LNAME2 type-seq-instantiation, Type sequence instantiation))
229228

230229
$(H3 $(LNAME2 value-seq, Value sequences))
231230

232-
$(P It is possible to use value sequences with values of the same type to declare array literals:)
231+
$(P It is possible to use a sequence of values of the same type to declare an array literal:)
233232

234233
---
235234
import std.meta;
236-
static assert ([ AliasSeq!(1, 2, 3) ] == [ 1, 2, 3 ]);
235+
enum e = 3;
236+
enum arr = [ AliasSeq!(1, 2, e) ];
237+
static assert(arr == [ 1, 2, 3 ]);
237238
---
238239

239-
$(H3 $(LNAME2 symbol-seq, Symbol sequences))
240+
$(P The above sequence is an $(I rvalue sequence), as it is comprised only of literal values
241+
and manifest constants. Each element's value is known at compile-time.)
242+
243+
$(P The following demonstrates use of an $(I lvalue sequence):)
244+
---
245+
import std.meta, std.algorithm;
246+
auto x = 3, y = 7;
247+
alias pair = AliasSeq!(x, y);
248+
swap(pair);
249+
assert(x == 7 && y == 3);
250+
---
251+
$(P As above, such sequences may use $(ALOCAL assignment, assignment).)
252+
253+
$(H4 $(LNAME2 tupleof, Aggregate field sequences))
240254

241255
$(P $(DDSUBLINK spec/class, class_properties, `.tupleof`) is a
242-
class/struct instance property that provides a symbol sequence
243-
of fields.)
256+
class/struct instance property that provides an lvalue sequence
257+
of each field.)
258+
259+
$(H3 $(LNAME2 symbol-seq, Symbol sequences))
244260

245-
)
261+
$(P A symbol sequence aliases any named symbol - types, variables, functions and templates -
262+
but not literals.
263+
Like an alias sequence, the kind of elements can be mixed.)
246264

247265
Macros:
248266
TITLE=Compile-time Sequences

0 commit comments

Comments
 (0)