MetaVar..Do
MetaVar x := expr Do body
Declares a local variable with identifier «x», and assigns it an initial value obtained by evaluating «expr». The identifier «x» can then be referred to within the «body» expression. The expression «body» is said to be the lexical context of «x», since outside of the lexical context, the identifier «x» is not recognized. MetaVar..Do is identical to Var..Do when the value assigned to «x» contain no handles and is not a 1-D null-indexed list. When implementing Meta-Inference algorithms that reason about or manipulate Analytica objects, MetaVar..Do is usually preferred to Var..Do in that its treatment of handles is more consistent and easier to understand than that of Var..Do.
MetaVar..Do is often used in a procedural syntax, where the declaration is followed by a semi-colon and the Do keyword is omitted, such as:
MetaVar root := isin of self;
While (isin of root <> null) Do root := isin of root;
root
The identifier, in this case root, exists from the expression immediately following the semi-colon until the end of the immediate lexical context that MetaVar..Do appears in.
Interpretation of «x» within «body»
Whenever the identifier for «x» appears within «body», it consistently represents the value held by «x». The important distinction between a local variable declared using MetaVar..Do, compared to a local declared by Var..Do or LocalAlias..Do occurs when «x» is set to a handle. In this case, «x» represents the handle, which is a type of atomic value, just like a number or text value is a type of atomic entity. This is contrasted to locals declaring via Var..Do or LocalAlias..Do which serve as an alias to the variable pointed to by the handle. Examples:
Suppose
Variable Va1 := 3
Then:
MetaVar x:= Handle(Va1) Do [x] → [Va1]
MetaVar x:= Handle(Va1) Do [Evaluate(x)] → [3]
Var x:= Handle(Va1) Do [x] → [3]
LocalAlias x := Handle(Va1) Do [x] → [3]
To access the value of the variable pointed to by a MetaVar local, use Evaluate(«x»), as in the second example.
If you assign a list value to the meta-variable, you cannot use the local identifier where an index is expected. So, for example, this would not be allowed:
MetaVar x:= 1..5 Do Sum(x^2, x) { not allowed }
So, unlike Var..Do, even though MetaVar..Do may create an implicit dimension, you can't refer to that dimension using the name of the local variable. If you intend to do that, you probably want to be using MetaIndex..Do. On the other hand, if you assign the meta-local a handle to an index, then you can use the identifier in an index context.
Dimensionality Declaration
Like Var..Do, MetaVar..Do supports the same dimensionality declarations, i.e.:
- MetaVar «x»[«indexList»] := «expr» Do «body»
To declare «x» to be atomic (zero-dimensional) use
- MetaVar «x»[] := «expr» Do «body»
or the equivalent shortcut:
- Atomic «x» := «expr» Do «body»
History
As of Analytica 4.2, a parameter of a User-Defined Function declared as (x : Handle) behaves like a local variable declared via MetaVar..Do.
Enable comment auto-refresher