[ ]

Syntax [expression]

or,

identifier [expression]

Action These two forms of the bracket operator have very different meanings. In the first form above, expression is evaluated as a string, and the result is then treated as an identifier.

Identifiers are the names of objects in the database and in scripts, which normally must consist strictly of alphanumeric characters (and possibly underscores). The bracket operator allows strings that contain spaces or other special characters to be used

as identifiers. It also allows a simple identifier to be replaced by a calculation of any kind.

The second form above is referred to as an array operation. In this case, identifier must specify a table, list, record, string or binary value, and expression specifies an item in that value. For tables and records, the item may be specified either by

index (a number) or by name (a string). For other value types, the item must be specified by index. The first item in an array has an index of one.

Examples 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.

Notes When expression is a string and the array value is a table, there is no functional difference between using the string in an array operation and using it as a bracketed identifier in a dotted id. That is:

identifier [expression]

identifier.[expression]

both specify the table item whose name matches the result of expression.

In addition to the requirement that identifiers contain only alphanumeric characters and underscores, they must not begin with a number, and cannot be the same as a reserved word of the UserTalk language. So if you need to create or refer to an object

named while, the bracket operator must be used as shown in the first example above to prevent the name from being mistaken as a looping statement.

See Also .

@

=

"{ }"

sizeOf

nameOf

address

Discuss