Alloy uses variables to store and access state of the workflows and actions. Variables can be accessed by app, actions, and their tasks. Each variable is referred by its name. Variable's name may contain letters, digits, and underscores.

Variables may have no value (aka. nil, NULL, etc.). It is about particular task's implementation how to interpret such values: some tasks may ignore it, others may use default values in such case - e.g. 0 or empty string.

Type defines kind of data held by variables. Alloy supports dynamic-typing, which means that Type of variable is exactly defined by its data after assignment. Each Type defines its own set of properties, which can be accessed by . operator. For example, to access address of a location stored in the homeLocation variable you may use homeLocation.address expression. Access to non-existent properties is safe and returns no result.

In addition to property access operator, other operators can be used with variables. The following are all allowed operators:

.

property access. Accesses a property of the variable in the form variable.property e.g. homeLocation.address.country

*

indirect addressing. Accesses value of another variable referenced by variable itself in the form *variable. For example, if locations variable contains "savedParking" string - *locations expression returns locations stored in the savedParking variable.

|

choice. This operator may be used only in macro to list several variables to choice in the form $(variable1 | variable2 | variable3). When choice operator is used - the first variable in the list that has value will define result for macro. For example, $(contact.firstName | contact.lastName) will result last name of a contact if first name is not specified.

 =

assignment. This operator is allowed to use in two cases:

In the "Initialize Variables" task to assign new values to variables. The "Variables" expression may contain several variables' initializations where each initialization occupies one line in form variable = initializers. Initializers can be either number, string or JSON to define Lists and Maps.

To define default value to a macro result if macro variable has no value. For example, macro $(name="Kate") results either textual value of name variable or "Kate" if name variable has no value.

+

appends an element to a List. See List for detailed description

[]

access an element of List and Map. See List and Map types for detailed description

,

enumeration. Enumerates several variables in form variable1, variable2, etc. This operator can be used in Tasks' Out property to define several variables which should get the same value. For example, location,+locations stated in the Out property of a "Get Location" task would result that newly obtained location will be assigned to the location variable and appended to the locations list.

Note: Alloy tries to guess Type of variables in the Action and Task editors, and presents available properties in the Variables' Keyboard. Though, current implementation may not discover correct Types in some cases. So if you know correct type of a variable - you can manually type its properties.


See also:
Variable Types
Tasks and Workflows
Actions

Next > Macro