Attrib of Obj
(enhanced in 4.0)
Attrib Of Obj
Returns the value of attribute Attrib of the object identified by Obj.
(new to 4.0) If the requested attribute is not set, returns Null.
Examples:
- Units of Time → 'Years'
or
- 'Units' of 'Time' → 'Years'
Library
Special
Using Computed Parameters
Both parameters, Attrib and Obj, can be either statically or dynamically bound, which is to say, the identification of the attribute and object can be made either at parse time or at evaluation time. Often in Meta-Inference algorithms, the attribute or object is a computed value, and thus the attribute or object isn't completely identified until the expression is evaluated.
If the Attrib parameter preceding the OF keyword is a literal attribute name, then it is bound at parse time. In this case only, the OF keyword is optional. Otherwise, if the parameter preceding OF is any other expression, the expression is evaluated at run time, but must evaluate either to text containing the attribute name, to a varTerm of an attribute object, or to a list or array containing these, otherwise an error results.
If the Obj parameter following the Of keyword is an object identifier, then obj is bound at parse time. This means that the attribute of the named object is returned, not the attribute of the object computed by the variable. When using Attrib OF Obj in a meta-inference algorithm, you must keep this straight. The following example demonstrates. Suppose global Variable objects, Va1 and Va2, are defined by expressions that identify an object, A, i.e.:
Variable Va1 := VarTerm(A) Variable Va2 := 'A'
Then OF in the following cases evaluate as shown:
Identifier Of Va1 → 'Va1' { statically bound } Identifier of Va2 → 'Va2' { statically bound }
To dynamically reference the object computed by a variable, you must write the Of expression in such a way that the Obj parameter is not itself a valid object identifier. There are two method for doing this - using a local variable declared with Var..Do (which is just an alias for a value, and not a object that has identifiers), or by calling a function that returns the computed object identification. In either case, the resolved value can be either a textual identifier of the desired object, a varTerm, or a list or array of these. In the above examples, the several variations are possible:
Var v:=Va1; Identifier Of v → 'A' Var v:=Va2; Identifier Of v → 'A' Identifier Of Value of Va1 → 'A' Identifier Of Mid(Va1) → 'A' Identifier Of Evaluate('Va1') → 'A' Identifier Of Evaluate(Va1) → 'A'
The Of operator parses in a right-associative fashion, so that the third line above parses as (Identifier Of (Value of Va1)).
Of can be used to retrieve attributes of functions, so for example,
Description Of Evaluate
returns the description of the evaluate function, while
Description Of Evaluate('Va1')
returns the description of Va1.
Of binds more tightly than the x^y operator, but less tightly than the Subscript/Slice Operator. So, for example, to access an attribute of a local index of an object, parens are not necessary:
index I := 1..2; Description of I := "A simple index"; Var A := I^2; Description of A.I & "=" & A
The last line parses as
((Description of (A.I)) & "=") & A
Assigning Values to Attributes
In certain circumstances, you can set the value of attributes using the syntax:
attrib Of obj := expr
The same considerations as to whether attrib and obj are statically bound or dynamically resolved apply. For most attributes, expr should to evaluate to text, although some attributes expect numbers. An example is this:
nodeColor of Va1 := '16000,8000,65535'
If you use assignment directly from a script (as opposed to using it from a definition attribute, such as a User-Defined Function called from a script), you must surround the expression with parens, i.e.
(nodeColor of Va1 := '16000,8000,65535')
This is because typescript has its own syntax, and an assignment expression qualifies as valid typescript, but is interpreted differently (the right-hand side is not evaluated in typescript). The parentheses identify this to the typescript interpreter as an expression, rather than a typescript command.
Because Analytica imposes restrictions on side-effects, so that it can maintain dependencies among variables consistently, assignment to attributes of global objects is not permitted while a variable is being evaluated. You may assign to attributes of local indexes (declared using Index..Do) at any time, but assignment to attributes of global objects is only permitted from typescript (e.g., from a button's Script attribute), or from a function that is invoked from typescript.
You also cannot assign to read-only attributes (usually internal attributes computed by Analytica).
To remove an attribute value, assign it to Null:
Units of Va1 := Null
Note: Internally, Analytica distinguishes between an attribute set to the special value Null, and and attribute that has no value. However, it is not possible to set an attribute value to Null from an Analytica expression (although you can set value to lists or arrays containing Null elements).
When assigning to the definition attribute, the right-hand side should evaluate to a text string, e.g.:
Definition of Va1 := "A" & "+" & "B"
Note that when you assign directly to a variable, the definition is set to a literal or to an edit table of literals equal to the actual value. (Va1 := "A"&"+"&"B") would set the definition to 'A+B' (with quotes), rather than just A+B (an expression without quotes).
Dependency Maintenance
Analytica's dependency maintenance mechanism does NOT maintain dependencies between arbitrary attributes. So, for example, if you have a variable, Va2, that references the Description of Va1 from within its definition, once Va2 is computed it will not be automatically refreshed or invalidated in the event that the description of Va1 changes.
Enable comment auto-refresher