List Types
A list holds any number of elements between a pair of delimiters. There are three, and the delimiters decide what the evaluator does with one:
| Type | Written | Evaluating it gives | Antiform |
|---|---|---|---|
BLOCK! | [a b] | the block itself, unevaluated | SPLICE! |
GROUP! | (a b) | the result of running it | PACK! |
FENCE! | {a b} | a block bound into a new context, for MAKE or EVAL | DATATYPE! |
>> [1 + 2]
== [1 + 2]
>> (1 + 2)
== 3
>> any-list? first [{a: 1}]
== \~okay~\ ; antiform (logic!)
Lists Are Series
Lists work much as they did in historical Rebol. Each is a series: a list value has a position in it, and the same items can be seen from more than one position. NEXT, BACK, SKIP and INDEX OF move and report the position, and APPEND, INSERT, CHANGE and REMOVE modify the list in place:
>> next [a b c]
== [b c]
>> index of next [a b c]
== 2
>> append copy [a b] 'c
== [a b c]
What’s different is about who may modify a list. A literal list in a function body is read-only unless you say otherwise, so that the classic bug of a [] in a body silently growing on each call can’t happen. See Constness.
Lists also keep the line breaks they were written with, which is how code that’s been loaded and molded back out still looks like what was written.
Lists Compared to Sequences
The other kind of container is the sequence: a/b, a.b, a:b. Sequences aren’t series. They’re immutable, have no position, and have rules about what they can hold. To work on one as if it were a list, convert it to a block and back:
>> as block! 'a/b/c
== [a b c]
>> as path! [a b c]
== a/b/c
See Also
- Sequence Types – the immutable containers
- Constness – when a list may be modified
- Evaluation – why BLOCK! and GROUP! evaluate differently