Tinderbox v10 Icon

Square brackets: lists and nested lists

Square brackets in action code were originally added to deal with the problem of nested lists, i.e. where a list item is itself a list. This first became an issue when the Dictionary data type was added and users wished to have keys with multiple values. As a dictionary is a semicolon delimited list of key;value paired terms, if a value were also a list where does the key:value pair end.

To overcome this a list item value in a List or Set that is a list, or a Dictionary key value that is itself a list, i.e. a nested list, can be marked with [ ] brackets:

$MyList = [places;[apples;oranges];plants]; 

Furthermore, the [ ] is used to define a complete list:

$MyList = [places;plants]; 
$MyList = [places;[apples;oranges];plants]; 

this replaces the older, and still working—but deprecated— quote enclosed form:

$MyList = "places;plants"; 

Importantly, note how in the first examples above the brackets replace the use of quotes as seen in the last example.

Note that, being new, at present very few code examples use this notation although it is now to be considered best practice new code when defining lists. Especially for those used to using quotes the old form still works but avoid these mixed forms, which may not work or have unexpected outcomes:

$MyList = "[places;plants]"; WRONG
$MyList = ["places;plants"]; WRONG

If it is necessary to define a list where the list item(s) need to first be evaluated, use the list() operator.

Here is a further example using Dictionary-type data where a key's value needs to be a list First in the new { } dictionary notation:

$MyDictionary = {dog:terrier;boat:yawl;fruit:[apple;pear]};

and now in the older (still working) format:

$MyDictionary = dictionary("dog:terrier;boat:yawl;fruit:[apple;pair]");

See also—notes linking to here: