Difference between revisions of "Evaluate"

(Var..Do --> Local..Do)
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[category:Evaluation Functions]]
 
[[category:Evaluation Functions]]
[[Category:Doc Status C]] <!-- For Lumina use, do not change -->
+
{{ReleaseBar}}
  
 +
Evaluate(t) is a powerful, but rarely needed function. If t is text, it parses it as an Analytica expression and evaluates it. If t is a handle to a variable, it evaluates and returns its value.
 
== Evaluate(t) ==
 
== Evaluate(t) ==
  
[[Evaluate]] expects a [[Text values|text value]] «t», and evaluates it as though it were an [[expression]] in a [[definition]]. It returns the [[value]] resulting from evaluating the expression. For example:
+
If parameter «t» is a [[Text values|text value]],  [[Evaluate]](«t») tries to parse «t» as an Analytica [[expression]] (as in the [[definition]] of a Variable), evaluates it, and returns the resulting [[value]]. For example:
  
:<code>Evaluate('10M /10') &rarr; 1M</code>
+
:<code>Evaluate('10 * 10') &rarr; 100</code>
  
If «t» contains any syntax errors, [[Evaluate]] returns [[Null]]; it will not flag a syntax error.
+
If parameter «t» is a [[Handle]] to a variable, [[Evaluate]](«t») evaluates the variable and returns its value:
 +
:<code>Variable A := 100</code>
 +
:<code>[[Evaluate]]([[Handle]](A)) &rarr; 100</code>
 +
 +
You can also use it to evaluate a function passed as an object or handle:
 +
:<code>Function Add(a, b)  :=  a+b</code>
 +
:<code>[[Evaluate]]([[Handle]](Add), 2, 10) &rarr; 12</code>
 +
This can be useful when you  want to define a function that takes a function as a parameter and applies the function in its body.
 +
See [[#Using Evaluate on a Function]] below.
  
One use for [[Evaluate]] is to convert (coerce) a text representation of a number into the number itself, for example:
+
== Limitations of Evaluate(t) ==
  
:<code>Evaluate('100M') &rarr; 100M</code>
+
There are some subtleties and limitations to Evaluate(«t») when «t» is a text value.
  
Like most other [[functions]], it returns the deterministic ([[Mid]]) or probabilistic value, according to the context in which it is called. [[Evaluate]] is powerful, and useful for a variety of purposes, but, it has some subtle aspects. Consider:
+
If text «t» contains a  [[syntax]] error, [[Evaluate]](«t») gives no error message, and returns [[Null]].
  
:<code>Variable A := 99</code>
+
The context inside the  Evaluate parameter is global, not local. So:
:<code>Variable B := (VAR A := 0; Evaluate('A + 1'))</code>
+
:<code>Variable A := 100</code>
:<code>B &rarr; 100</code>
+
:<code>Variable B := ([[Local]] A := 0; [[Evaluate]]('A + 1'))</code>
 +
:<code>B & rarr; 101</code>
  
The Variable <code>A</code> in the evaluated text <code>'A + 1'</code> refers to the global <code>A</code>, not the local <code>A</code> defined in <code>B</code>. More generally:
+
The Variable <code>A</code> inside <code>Evaluate('A + 1')</code> refers to the global <code>A</code>, not the local <code>A</code> defined in <code>B</code>. More generally:
 
 
* [[Evaluate]](t) creates its own context for [[Parsed Expressions|parsing]] «t» (at evaluation time), which is quite separate from the context of the expression in which the [[Evaluate]](t) appears.e.g., the definition of <code>B</code> above.
 
* So, text «t» cannot refer to [[local variable]]s, [[index]]es, or [[function parameters]] defined in the context in which the [[Evaluate]](t) function appears.
 
* If the text value of «t» refers to any global variables—e.g., <code>A</code> in the definition of <code>B</code> above—these will not appear as Inputs of <code>B</code>, nor will any changes to <code>A</code> cause automatic re-evaluation of <code>B</code>.
 
* Text «t» may itself define local Variables and indexes, and refer to them, but these will not be available outside «t».
 
* When [[Evaluate]] references another variable, Analytica will not be able to track the dependency. For example:
 
  
 +
* [[Evaluate]](t) creates its own context for [[Parsed Expressions|parsing]] «t» (at evaluation time), which is not the context of the expression in which the [[Evaluate]](t) appears  -- e.g., the definition of <code>B</code> above.
 +
* So, text «t» cannot refer to [[Local Values|local value]]s, [[index]]es, or [[function parameters]] defined in the context in which the [[Evaluate]](t) function appears.
 +
* Text «t» may itself define local values and indexes, and refer to them, but these will not be available outside «t».
 +
* If the text value of «t» refers to a global variable —e.g., <code>A</code> in the definition of <code>B</code> above—these do not appear as Inputs of <code>B</code>.
 +
* More generally, Analytica cannot track the dependency of any variable name that appears inside the text. So, for example, any change to <code>A</code> will not cause automatic re-evaluation of <code>B</code>:
 +
:<code>A := 3</code>
 
:<code>B := A + 1</code>
 
:<code>B := A + 1</code>
 
:<code>C := Evaluate('A + 1')</code>
 
:<code>C := Evaluate('A + 1')</code>
 +
:<code>A := 5</code>
  
 
When <code>A</code> changes, Analytica will automatically ensure that <code>B</code> is updated, but it has no way of knowing <code>C</code> should also be recomputed.
 
When <code>A</code> changes, Analytica will automatically ensure that <code>B</code> is updated, but it has no way of knowing <code>C</code> should also be recomputed.
  
Text «t» may itself be an expression that creates a text value to be evaluated by [[Evaluate]]. This text expression appears in the definition of <code>V</code> and is not subject to the above limitations, so, for example:
+
The parameter «t» may itself be an expression that creates a text value to be evaluated by [[Evaluate]]. This text expression appears in the definition of <code>V</code> and is not subject to the above limitations, so, for example:
  
:<code>Variable V :=(Var x:= ’10’; Evaluate(x & x))</code>
+
:<code>Variable V :=([[Local]] x:= ’10’; [[Evaluate]](x & x))</code>
 
:<code>V &rarr; 1010</code>
 
:<code>V &rarr; 1010</code>
  
 
== When to Use ==
 
== When to Use ==
  
The cases in which you should use [[Evaluate]] are rare.  You should be very reluctant to use it due to the caveats listed in the previous section.
+
The cases in which you should use [[Evaluate]] are rare.  You should be reluctant to use it due to the caveats listed in the previous section. Typical cases when it is useful include:
 
+
* Parsing simple expressions.
Legitimate cases that do occasionally occur:
 
* Parsing numbers or simple expressions.
 
 
* (advanced) Use in [[Meta-Inference]] algorithms where you are manipulating handles to objects in your model.
 
* (advanced) Use in [[Meta-Inference]] algorithms where you are manipulating handles to objects in your model.
 
* (rare) Cases where you really do wish to by-pass dependency maintenance.  You want it to compute something the first time the result is requested after the model is first loaded, but not update when parent values are changes.
 
* (rare) Cases where you really do wish to by-pass dependency maintenance.  You want it to compute something the first time the result is requested after the model is first loaded, but not update when parent values are changes.
Line 49: Line 58:
 
== Non-text Parameters ==
 
== Non-text Parameters ==
  
A non-text value can also be passed to [[Evaluate]], which can be of use in some [[Meta-Inference]] applications.  You need to keep in mind that the parameter to evaluate is evaluated BEFORE the function itself gets it, so evaluating a non-text value is only meaningful when the evaluated parameter is itself something that can still be evaluated.  One instance of this that is often useful is the case of a [[varTerm]], i.e., a handle to an object.
+
A non-text value can also be passed to [[Evaluate]], which can be of use in some [[Meta-Inference]] applications.  You need to keep in mind that the parameter to evaluate is evaluated BEFORE the function itself gets it, so evaluating a non-text value is only meaningful when the evaluated parameter is itself something that can still be evaluated.  One instance of this that is often useful is the case of a [[handle]] an object.
  
 
For example, suppose  
 
For example, suppose  
 
:<code>Variable A := 2  + 3</code>
 
:<code>Variable A := 2  + 3</code>
:<code>Variable TheVar := VarTerm(A)</code>
+
:<code>Variable TheVar := [[Handle]](A)</code>
  
 
In the more general case, you might have a [[Meta-Inference]] algorithm that identifies a single variable object through some computation. Having identified the object, <code>TheVar</code> now holds a handle to the object.  You then may want to access values or properties of the object pointed to by <code>TheVar</code>, rather than just values or properties of <code>TheVar</code> itself.  Evaluate serves this purpose:
 
In the more general case, you might have a [[Meta-Inference]] algorithm that identifies a single variable object through some computation. Having identified the object, <code>TheVar</code> now holds a handle to the object.  You then may want to access values or properties of the object pointed to by <code>TheVar</code>, rather than just values or properties of <code>TheVar</code> itself.  Evaluate serves this purpose:
  
 
:<code>TheVar &rarr; A  { A -- i.e., a handle to the object A }</code>
 
:<code>TheVar &rarr; A  { A -- i.e., a handle to the object A }</code>
:<code>Evaluate(TheVar) &rarr; 5  { evaluates A }</code>
+
:<code>[[Evaluate]](TheVar) &rarr; 5  { evaluates A }</code>
  
It is worth nothing that an alternative method also exists for evaluating a [[varTerm]].  If you assign an existing [[varTerm]] ([[handle]] to an object) to a [[local variable]], that variable becomes an [[alias]] for the object [[identifier]].  If that local variable then appears in a value context, this also returns the value of the target variable:
+
It is worth nothing that an alternative method also exists for evaluating a [[handle]].  You can declare a [[LocalAlias]] set to the handle, and then use its identifier as if it were the identifier of the object.
  
:<code>Var x := TheVar Do x &rarr; 5    { x is an alias for A, so "x" in the body is the value of A }</code>
+
:<code>[[LocalAlias]] x := TheVar Do x &rarr; 5    { x is an alias for A, so "x" in the body is the value of A }</code>
  
 
When accessing attributes of an object in a [[Meta-Inference]] algorithm, where your algorithm has a handle to an object (again, say it is in <code>TheVar</code>), you can access the attribute using e.g.,
 
When accessing attributes of an object in a [[Meta-Inference]] algorithm, where your algorithm has a handle to an object (again, say it is in <code>TheVar</code>), you can access the attribute using e.g.,
Line 71: Line 80:
 
(the result of using <code>TheVar</code> alone is shown for comparison).
 
(the result of using <code>TheVar</code> alone is shown for comparison).
  
== Invoking Functions ==
+
== Using Evaluate on a Function ==
  
 
Given a [[handle]] to a function object, you can use [[Evaluate]] to call the function.  If the function expects ''N'' parameters, you would provide ''N+1'' parameters to [[Evaluate]] -- the first parameter being the handle to the function, and the remaining parameters being the values passed to the function.  Example:
 
Given a [[handle]] to a function object, you can use [[Evaluate]] to call the function.  If the function expects ''N'' parameters, you would provide ''N+1'' parameters to [[Evaluate]] -- the first parameter being the handle to the function, and the remaining parameters being the values passed to the function.  Example:
  
:<code>MetaVar fn := If opt = 1 then Handle(Max) else if opt = 2 then Handle(Min) else Handle(Sum);</code>
+
:<code>[[Local]] fn := [[If]] opt = 1 [[Then]] [[Handle]]([[Max]]) [[Else]] [[If]] opt = 2 [[Then]] [[Handle]]([[Min]]) [[Else]] [[Handle]]([[Sum]]);</code>
:<code>Evaluate(fn, A, I)</code>
+
:<code>[[Evaluate]](fn, A, I)</code>
  
 
Parameters to the function being called are always passed by position, i.e., you cannot use a named-parameter calling syntax as you might if you were calling the function directly.   
 
Parameters to the function being called are always passed by position, i.e., you cannot use a named-parameter calling syntax as you might if you were calling the function directly.   
Line 84: Line 93:
 
:<code> Function Fu1(x; y: repeated; z: optional) := ...</code>
 
:<code> Function Fu1(x; y: repeated; z: optional) := ...</code>
 
:<code>&nbsp;</code>
 
:<code>&nbsp;</code>
:<code>Evaluate(fn, 1, 2, 3, 4) &rarr;</code>  
+
:<code>[[Evaluate]](fn, 1, 2, 3, 4) &rarr;</code>  
 
::''Equivalent to <code>Fu1(1, 2, 3, 4)</code>, where <code>[2, 3, 4]</code> are values for <code>y</code> and <code>z</code> is omitted''
 
::''Equivalent to <code>Fu1(1, 2, 3, 4)</code>, where <code>[2, 3, 4]</code> are values for <code>y</code> and <code>z</code> is omitted''
:<code>Evaluate(fn, 1, [2, 3], 4) &rarr;</code>  
+
:<code>[[Evaluate]](fn, 1, [2, 3], 4) &rarr;</code>  
 
::''Equivalent to <code>Fu1(1, 2, 3, y: 4)</code>, where <code>[2, 3]</code> are values for <code>y</code>, and <code>z</code> is 4''.
 
::''Equivalent to <code>Fu1(1, 2, 3, y: 4)</code>, where <code>[2, 3]</code> are values for <code>y</code>, and <code>z</code> is 4''.
  
 
However, there is a limitation that the first supplied parameter (i.e., the second parameter to [[Evaluate]]) cannot be placed inside brackets.  Likewise, you cannot pass an literal list by specifying the first parameter as a bracketed list.  This is because the repeated-parameter syntax applies equally to [[Evaluate]].  If you specify the first parameter to [[Evaluate]] in brackets, those become the parameters to the function, i.e.,:
 
However, there is a limitation that the first supplied parameter (i.e., the second parameter to [[Evaluate]]) cannot be placed inside brackets.  Likewise, you cannot pass an literal list by specifying the first parameter as a bracketed list.  This is because the repeated-parameter syntax applies equally to [[Evaluate]].  If you specify the first parameter to [[Evaluate]] in brackets, those become the parameters to the function, i.e.,:
  
:<code>Evaluate(Handle(F), [1, 2, 3, 4]) &rarr;</code>  
+
:<code>[[Evaluate]]([[Handle]](F), [1, 2, 3, 4]) &rarr;</code>  
 
::''Equivalent to <code>F(1, 2, 3, 4)''</code>
 
::''Equivalent to <code>F(1, 2, 3, 4)''</code>
  
Several common built-in functions, including [[Sum]], [[Max]], and [[Min]], allow a variable number of indexes, so that you can use <code>Sum(A, I, J, K)</code> to sum over 3 dimensions in a single call.  These functions also have [[optional parameter]]s, such as «ignoreNonNumbers», so that if you need to specify these optional parameters, you will need to place brackets around the index(es), even if only one (or zero) index is specified.  For example, the following examples show how to to specify «ignoreNonNumbers» as true to [[Sum]], when summing over a single index, and when summing over the [[implicit dimension]]:
+
Several common built-in functions, including [[Sum]], [[Max]], and [[Min]], allow a variable number of indexes, so that you can use <code>[[Sum]](A, I, J, K)</code> to sum over 3 dimensions in a single call.  These functions also have [[optional parameter]]s, such as «ignoreNonNumbers», so that if you need to specify these optional parameters, you will need to place brackets around the index(es), even if only one (or zero) index is specified.  For example, the following examples show how to to specify «ignoreNonNumbers» as true to [[Sum]], when summing over a single index, and when summing over the [[implicit dimension]]:
  
:<code>Evaluate(Handle(Sum), A, [I], true)</code>
+
:<code>[[Evaluate]]([[Handle]]([[Sum]]), A, [I], true)</code>
:<code>Var x := [3, 2, 'a', 'b', 6] do Evaluate(Handle(Sum),  x, [], true)</code>
+
:<code>[[Local]] x := [3, 2, 'a', 'b', 6] do [[Evaluate]]([[Handle]]([[Sum]]),  x, [], true)</code>
  
 
Notice that if you don't need to specify the optional «ignoreNonNumbers» parameter (or any parameters that follow the repeated index parameters), then it is more natural to omit the brackets:
 
Notice that if you don't need to specify the optional «ignoreNonNumbers» parameter (or any parameters that follow the repeated index parameters), then it is more natural to omit the brackets:
  
:<code>Evaluate(Handle(Sum), A, I)</code>
+
:<code>[[Evaluate]]([[Handle]]([[Sum]]), A, I)</code>
:<code>Var x := [3, 2, 5, 3, 6] do Evaluate(Handle(Sum), x)</code>
+
:<code>[[Local]] x := [3, 2, 5, 3, 6] do [[Evaluate]]([[Handle]]([[Sum]]), x)</code>
 +
 
 +
{{Release|6.5||
 +
== Evaluating in a different namespace context ==
 +
''New to [[Analytica 6.5]]''
 +
 
 +
Suppose there are two variables that both have the identifier X, but which live in different [[Namespaces]]. Then
 +
:<code>[[Evaluate]]( "X+1" )</code>
 +
would differ depending on where it appears. By default it resolves the identifier <code>X</code> from the namespace of the object containing the expression. In some esoteric situations, you may need to interpret the expression from a different namespace context.  You can do this by first obtaining a handle to the other namespace module, or to any object inside that namespace, and passing that handle to the «nsContext» parameter.
 +
:<code>[[Evaluate]]( "X+1", nsContext: [[Handle]]("NS2") )</code>
 +
}}
  
 
== See Also ==
 
== See Also ==
 +
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[EvaluateScript]]
 
* [[EvaluateScript]]
 
* [[Proactive Evaluation]]
 
* [[Proactive Evaluation]]
 
* [[Evaluation Modes]]
 
* [[Evaluation Modes]]
* [[VarTerm]]
+
* [[Handle]]
 
* [[Expression Syntax]]
 
* [[Expression Syntax]]
 
* [[Expression Assist]]
 
* [[Expression Assist]]
Line 115: Line 135:
 
* [[Summary of Programming Constructs]]
 
* [[Summary of Programming Constructs]]
 
* [[Procedural Programming]]
 
* [[Procedural Programming]]
 +
* [[Meta-Inference]]{{Release|6.5||
 +
* [[Namespaces]]}}
 +
</div>

Revision as of 17:02, 23 July 2024

Release:

 • 4.6 •  5.0 •  5.1 •  5.2 •  5.3 •  5.4 •   •  6.0 •  6.1 •  6.2 •  6.3 •  6.4 •  6.5 •  6.6

Evaluate(t) is a powerful, but rarely needed function. If t is text, it parses it as an Analytica expression and evaluates it. If t is a handle to a variable, it evaluates and returns its value.

Evaluate(t)

If parameter «t» is a text value, Evaluate(«t») tries to parse «t» as an Analytica expression (as in the definition of a Variable), evaluates it, and returns the resulting value. For example:

Evaluate('10 * 10') → 100

If parameter «t» is a Handle to a variable, Evaluate(«t») evaluates the variable and returns its value:

Variable A := 100
Evaluate(Handle(A)) → 100

You can also use it to evaluate a function passed as an object or handle:

Function Add(a, b) := a+b
Evaluate(Handle(Add), 2, 10) → 12

This can be useful when you want to define a function that takes a function as a parameter and applies the function in its body. See #Using Evaluate on a Function below.

Limitations of Evaluate(t)

There are some subtleties and limitations to Evaluate(«t») when «t» is a text value.

If text «t» contains a syntax error, Evaluate(«t») gives no error message, and returns Null.

The context inside the Evaluate parameter is global, not local. So:

Variable A := 100
Variable B := (Local A := 0; Evaluate('A + 1'))
B & rarr; 101

The Variable A inside Evaluate('A + 1') refers to the global A, not the local A defined in B. More generally:

  • Evaluate(t) creates its own context for parsing «t» (at evaluation time), which is not the context of the expression in which the Evaluate(t) appears -- e.g., the definition of B above.
  • So, text «t» cannot refer to local values, indexes, or function parameters defined in the context in which the Evaluate(t) function appears.
  • Text «t» may itself define local values and indexes, and refer to them, but these will not be available outside «t».
  • If the text value of «t» refers to a global variable —e.g., A in the definition of B above—these do not appear as Inputs of B.
  • More generally, Analytica cannot track the dependency of any variable name that appears inside the text. So, for example, any change to A will not cause automatic re-evaluation of B:
A := 3
B := A + 1
C := Evaluate('A + 1')
A := 5

When A changes, Analytica will automatically ensure that B is updated, but it has no way of knowing C should also be recomputed.

The parameter «t» may itself be an expression that creates a text value to be evaluated by Evaluate. This text expression appears in the definition of V and is not subject to the above limitations, so, for example:

Variable V :=(Local x:= ’10’; Evaluate(x & x))
V → 1010

When to Use

The cases in which you should use Evaluate are rare. You should be reluctant to use it due to the caveats listed in the previous section. Typical cases when it is useful include:

  • Parsing simple expressions.
  • (advanced) Use in Meta-Inference algorithms where you are manipulating handles to objects in your model.
  • (rare) Cases where you really do wish to by-pass dependency maintenance. You want it to compute something the first time the result is requested after the model is first loaded, but not update when parent values are changes.

Non-text Parameters

A non-text value can also be passed to Evaluate, which can be of use in some Meta-Inference applications. You need to keep in mind that the parameter to evaluate is evaluated BEFORE the function itself gets it, so evaluating a non-text value is only meaningful when the evaluated parameter is itself something that can still be evaluated. One instance of this that is often useful is the case of a handle an object.

For example, suppose

Variable A := 2 + 3
Variable TheVar := Handle(A)

In the more general case, you might have a Meta-Inference algorithm that identifies a single variable object through some computation. Having identified the object, TheVar now holds a handle to the object. You then may want to access values or properties of the object pointed to by TheVar, rather than just values or properties of TheVar itself. Evaluate serves this purpose:

TheVar → A { A -- i.e., a handle to the object A }
Evaluate(TheVar) → 5 { evaluates A }

It is worth nothing that an alternative method also exists for evaluating a handle. You can declare a LocalAlias set to the handle, and then use its identifier as if it were the identifier of the object.

LocalAlias x := TheVar Do x → 5 { x is an alias for A, so "x" in the body is the value of A }

When accessing attributes of an object in a Meta-Inference algorithm, where your algorithm has a handle to an object (again, say it is in TheVar), you can access the attribute using e.g.,

Description Of Evaluate(TheVar) → "Description of A"
Description Of TheVar → "Description of TheVar"

(the result of using TheVar alone is shown for comparison).

Using Evaluate on a Function

Given a handle to a function object, you can use Evaluate to call the function. If the function expects N parameters, you would provide N+1 parameters to Evaluate -- the first parameter being the handle to the function, and the remaining parameters being the values passed to the function. Example:

Local fn := If opt = 1 Then Handle(Max) Else If opt = 2 Then Handle(Min) Else Handle(Sum);
Evaluate(fn, A, I)

Parameters to the function being called are always passed by position, i.e., you cannot use a named-parameter calling syntax as you might if you were calling the function directly.

If the function being called contains repeated (or variable number of) parameters, and you need to include a parameter that follows the repeated parameter, then you must place brackets around the repeated parameters. For example,

Function Fu1(x; y: repeated; z: optional) := ...
 
Evaluate(fn, 1, 2, 3, 4) →
Equivalent to Fu1(1, 2, 3, 4), where [2, 3, 4] are values for y and z is omitted
Evaluate(fn, 1, [2, 3], 4) →
Equivalent to Fu1(1, 2, 3, y: 4), where [2, 3] are values for y, and z is 4.

However, there is a limitation that the first supplied parameter (i.e., the second parameter to Evaluate) cannot be placed inside brackets. Likewise, you cannot pass an literal list by specifying the first parameter as a bracketed list. This is because the repeated-parameter syntax applies equally to Evaluate. If you specify the first parameter to Evaluate in brackets, those become the parameters to the function, i.e.,:

Evaluate(Handle(F), [1, 2, 3, 4]) →
Equivalent to F(1, 2, 3, 4)

Several common built-in functions, including Sum, Max, and Min, allow a variable number of indexes, so that you can use Sum(A, I, J, K) to sum over 3 dimensions in a single call. These functions also have optional parameters, such as «ignoreNonNumbers», so that if you need to specify these optional parameters, you will need to place brackets around the index(es), even if only one (or zero) index is specified. For example, the following examples show how to to specify «ignoreNonNumbers» as true to Sum, when summing over a single index, and when summing over the implicit dimension:

Evaluate(Handle(Sum), A, [I], true)
Local x := [3, 2, 'a', 'b', 6] do Evaluate(Handle(Sum), x, [], true)

Notice that if you don't need to specify the optional «ignoreNonNumbers» parameter (or any parameters that follow the repeated index parameters), then it is more natural to omit the brackets:

Evaluate(Handle(Sum), A, I)
Local x := [3, 2, 5, 3, 6] do Evaluate(Handle(Sum), x)

Evaluating in a different namespace context

New to Analytica 6.5

Suppose there are two variables that both have the identifier X, but which live in different Namespaces. Then

Evaluate( "X+1" )

would differ depending on where it appears. By default it resolves the identifier X from the namespace of the object containing the expression. In some esoteric situations, you may need to interpret the expression from a different namespace context. You can do this by first obtaining a handle to the other namespace module, or to any object inside that namespace, and passing that handle to the «nsContext» parameter.

Evaluate( "X+1", nsContext: Handle("NS2") )

See Also

Comments


You are not allowed to post comments.