NOTE: in this article 'list' refers to use in both List and Set type data.
The List (or Set) operator: declaring lists using literal values
This explicitly converts a String to a List. That used to be important, but the introduction of typed local variables makes these unnecessary in many cases.
The preferred usage is for declaring lists (List or Set) is [… ]
A List or Set is declared using enclosing square brackets and without enclosing quotes:
var:list vList = [peach;orange;apple];
Deprecated: in the past, defining literal list values involved using a quote-enclosed semicolon delimited list:
var:list vList = "peach;orange;apple";
N.B. Both forms work equally well—at least for now.
However, the bracket-enclosed method is now the preferred syntax for writing list in new code. In due course aTbRef will update most examples to the newer format.
Declaring Nested lists
The new form of list definition also allows declaration of nested lists:
var:list vMatrix = [[0;1;2];[3;4;5];[6;7;8];[9;10;11]];
$Text = vMatrix[1];
This returns the result, [3;4;5], i.e. a List-type value containing a 3-item list.
Nested lists and Zip-method linking
Typing the syntax for nested links can involve character sequences like [[
and ]]
which are other wise use with the 'zip' method of making Tinderbox links. the latter can be suppressed for the current note by altering the $Ziplinks system attribute.
Strings In Lists
Take caution mixing quotes and square brackets:
var:list vList = ["peach;orange;apple"];
→ single item list
This creates a list with one element: the string "peach;orange;apple". This is needed very occasionally, e.g. for a string value legitimately needing to hold a semi-colon, such as might occur when doing manipulation of $Text content. If inspecting the list value in Displayed Attributes or Get Info/attributes, such a string list value is easily spotted as it is enclosed in the 'raw' list value using double quotes. This is a four-item list with a single 'string' item value as the third list item.
[rock;eel;"peach;orange;apple";monkey]
By comparison:
var:list vList = "[peach;orange;apple]";
→ three item list, but see next example...
In fact, the latter is a redundant form of the new bracketed declaration:
var:list vList = [peach;orange;apple];
but which might be typed in error by someone more used to the original from of defining a list.
The list() operator
Occasionally, it may be necessary to declare a list form evaluated expressions. The list() operator is used for that task.
Evaluation of [] list terms
Implicit evaluation is no longer performed in bracketed lists. For example,
$DisplayedAttributes=[MyList;MyString];
is now equivalent to
$DisplayedAttributes="MyList;MyString";
If list terms need evaluation, use list() instead.