MetaVar..Do

Revision as of 09:36, 3 January 2009 by Lchrisman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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. 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:= identifier 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 ]
Var x:=Handle(Va1) Do [x] → [ 3 ]
LocalAlias x := Handle(Va1) Do [x] → [ 3 ]

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»

Other notes

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.

See Also

Comments


You are not allowed to post comments.