Data Type Functions

Revision as of 08:49, 16 August 2010 by Psanford (Talk | contribs) (Function IsNull)


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 IsHandle

New to Analytica 4.2

IsHandle( X : Atom )
IsHandle( X, local:true )

Tests whether the value in X is a handle. When «X» is array-valued, it tests whether each cell of the array contains a handle. The second form with local:true tests whether a local variable «X» contains a handle. For details, see IsHandle.

Function IsNaN

IsNaN( X : Atom )

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 : Atom ) 

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 : Atom ) 

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 : Atom )

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 IsNull

Requires Analytica 4.2

IsNull( X )

Returns True if X is exactly Null. Returns false when X is another than Null. Does not array abstract, so if X is an array, even an array containing Null cells, it still returns atomic False. If you want to compare the cells of an array individually to Null, use x=Null. If you want to test whether an attribute is set, use

IsNull( attrib Of obj )

which will return false (0) if the attribute happens to contain an array with Null.

Note that IsNull is different from the other IsXXXX function in that it does not array abstract.

Function IsNotSpecified

IsNotSpecified( X : Atom )

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 : Atom ; 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:

  • "Number" - whenever IsNumber(X)
  • "Text" - whenever IsText(X)
  • "Null" - whenever X = Null
  • "Reference" - whenever IsReference(X)

The above cases are uneffected by the optional Shallow parameter.

In Analytica Optimizer, LpDefine, QpDefine or NlpDefine, each create an optimization object. For these objects, TypeOf(x) gives:

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

In these cases, TypeOF(X, Shallow: True) returns "Custom", indicating an internal object customized for a particular function library.

Analytica atoms can, in some cases, contain object handles. See Meta-Inference. For example, a Handle can be obtained using HandlefromIdentifier("X"). When X is a Handle, TypeOf(X) returns:

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

If X is a handle, TypeOf(X, Shallow: True) returns "Object".

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.