Data Type Functions

Analytica provides several functions for checking the data type of atoms (i.e., the items in an array). These are found in the Special library.

Function IsNaN

IsNaN( X : Atomic )

NaN is a special value arising from indeterminate arithmetic operations indicating "Not A Number". NaN can arise from operations such as:

0 / 0
0 * INF
INF - INF 
IgnoreWarnings(Ln(-1))
IgnoreWarnings(Sqrt(-1))

The last two cases result in NaN since Analytica does not have internal support for complex numbers. The other cases result because the result is indeterminate.

IsNaN(X) returns 1 (i.e., true) when X is the special value NaN, 0 (false) otherwise.

Function IsNumber

IsNumber( X : Atomic ) 

Returns true when X is a number, or any of the special values INF, -INF, or NaN.


Function IsReference

Returns 1 (true) when X is a reference, 0 otherwise. When X is a reference, you can use the #X operator.

Function IsText

IsText( X : Atomic ) 

Returns 1 (true) when X is a textual string, 0 otherwise.

Comparison to Null

The expressions X=Null or X<>Null can be used to test whether X is the special system constant Null. Null results from certain operations where the value is not found, such as A[I=X] when X is not an element of I (and warnings are ignored).

Null can also be detected using IsUndef(X).

Function IsUndef

IsUndef(X : Atomic )

Returns True if X is either of the two special system constants Undefined or Null. Undefined is a special system constant indicating that an attribute does not yet have a value, and also used to indicate that a value is not yet computed (e.g., that the (mid) value or probValue attribute do not yet have a value), or that an optional parameter to a function was not specified. Null is a value returned by function evaluations indicating that a requested value is out-of-range or does not exist.

The special value Null was introduced into Analytica 3.0. Prior to that, many functions returned Undefined when values did not exist, but were changed to return Null. To handle backward compatibility where the IsUndef function was being used to test for these values, IsUndef returns true in both cases.

Function IsNotSpecified

IsNotSpecified( X : Atomic )

Used within a user-defined function to determine whether an optional parameter has a value. If the optional parameter is not specified in the function call, and if the parameter has no default value, then IsNotSpecified returns true.

For example:

 Function Fu1( A : Numeric ; B : optional numeric )
 Definition: 
       if IsNotSpecified(B) Then B := sqrt(A);
       Normal(A*Time,B*sqrt(T))

Function TypeOf

TypeOf( X : Atomic ; Shallow : optional boolean )

(New to Analytica 4.0)

Returns the name of the atomic data type of X as a textual string. When TypeOf is applied to an array, the result is an array, where each cell contains the data type of the corresponding item in the original array.

The common return values for TypeOf(X) are the following:

  • "Numeric" - whenever IsNumber(X)
  • "Textual" - whenever IsText(X)
  • "Null" - whenever X = Null
  • "Undefined" - whenever IsUndef(X) and X<>Null
  • "Reference" - whenever IsReference(X)

The above cases are uneffected by the optional Shallow parameter.

In Analytica Optimizer, optimization programs are defined by LpDefine, QpDefine or NlpDefine, and create an optimization object. For these objects, the following values result when Shallow is not specified or is false:

  • "«LP»" - An object returned by LpDefine
  • "«QP»" - An object returned by QpDefine
  • "«NLP»" - An object returned by NlpDefine

When Shallow is specified and set to True, each of these cases return "Custom", indicating an internal object instance customized for a particular function library.

Analytica atoms can, in some cases, contain object handles (aka varTerms). See Meta-Inference. For example, a VarTerm can be obtained using GetVariableByName("ident"). When TypeOf(X) is applied to a varTerm, the following values result when Shallow is not specified or is False:

  • "Decision"
  • "Variable"
  • "Chance"
  • "Objective"
  • "Constant"
  • "Index"
  • "Function"
  • "Determ"
  • "Module"
  • "Module"
  • "Library"
  • "Form"
  • "Linkmodule"
  • "Linklibrary"
  • "Text"
  • "Button"
  • "Picture"
  • "Formnode"
  • "Alias"
  • "Attribute"
  • "Command"
  • "Graphstyletemplate"
  • "Sysfunction"
  • "Keyword"

In these cases, if Shallow is set to true, then the value "Object" is returned in the above cases.

In addition, there are some cases in which atomic values could contain special internal system data types. These are uncommon in normal modeling, but can occur, for example, by making use of "attrib of Obj". For example, an expression is obtainable using: fixeddef of Va1, when Va1 is defined as A+B. In these cases, the following values may result:

  • "Expression" - A parsed expression where the outermost operation is an operator. E.g., in a fixeddef
  • "FunctionCall" - An expression where the outermost operation is a function call, e.g., in a fixeddef attribute
  • "Keyword"
  • "ObjectSet" - e.g., in a input or output attribute
  • "Data" - e.g., in a Pict attribute

The parameter to TypeOf is evaluated. So, if you apply this to a function parameter or local variable, the type of the value is returned, even if the parameter is declared as an index or variable type. For example:

Function F1( A : Variable ) := TypeOf(A)

When you call F1(Ch1), the type of each atom in the value of Ch1 is returned -- not the class of Ch1. If you wanted the class of the object, it would be easiest to use:

Function F2( A : Variable ) := class of A

which would return "Chance" when call F2(Ch1).

Comments


You are not allowed to post comments.