edit (@examples. ["Sample Outline 1"])
» true
Sample Outline 1 contains spaces, and would normally be interpreted as two identifiers followed by a number - a syntax error, since it's not a valid expression. So we enclose the name in quotes, which groups the entire sequence of characters into a single
string value. The bracket operator then causes the string value to be treated as an identifier, allowing it to become part of the dotted id specifying the outline object.
sizeOf (people.[user.initials].notepad)
» 65
This example demonstrates how the bracket operator allow you to substitute an expression for an identifier. First, the expression user.initials is evaluated. The resulting value is used to name an item in the "people" table, the one belonging to the
current user. Finally, the item named "notepad" is referenced in the table specified by people.[user.initials]. The result indicates that the outline contains 65 headings.
defined (["system.verbs"])
» false
At first this can seem puzzling; there is a table named verbs in the system table. However, that's not what this expression specifies. The string "system.verbs", enclosed in the brackets, is interpreted as a single identifier, so the expression specifies
an object whose name is "system.verbs". No such object exists. When you want to interpret a string as a dotted path rather than an single identifier, use the address verb to coerce the value to an address.
nameOf (examples [5])
» counter
Here, we're using brackets as an array operation; note that there is no dot between examples and the first bracket. The simple expression "5" indicates the fifth item in the table. The nameOf operator returns the name of that item.
x = {"Jan", "Feb", "Mar"}; return (x [2])
ª "Feb"
x = "abcdef"; return (x [6])
ª 'f'
x = binary ("abcdef"); return (x [1])
ª 97
These examples show how you can use brackets to access an item in a list, a string, and a binary value respectively, treating the value as an array. The type of the item value depends on the type of the array value; an item in a string is a character,
while an item in a binary value is an unsigned byte represented by an integer value.