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 IsHandle

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 (see Ln, Sqrt and IgnoreWarnings). 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. It is also true when «X» is a complex number or a date-time number, since a date-time number is encoded as the number of days elapsed since the time origin. It returns false (zero) for text, even if the characters in the text could be parsed as a number.

Function IsRealNumber

IsRealNumber(X: Atom)

Returns True when «X» is a real number or the special values INF or -INF. It also returns true when «X» is a date-time number, since a date-time number is considered to be a numeric value -- the number of days elapsed since the date origin. It differs from IsNumber in that it returns false (zero) for a complex or imaginary number or for the special value NaN.

Function IsDateTime

IsDateTime(X: Atom)

Returns True when «X» is a date-time. A date-time is a special time of number in Analytica that encodes the number of days elapsed since the date origin, which is normally 1-Jan-1904, or 30-Dec-1899 if the "Use Excel Date Origin" preference is set. The fractional part of a date-time number represents a time. When printed, date-time numbers use the Date number format.

IsDateTime(X) is false for numbers other than those recognized as date-time numbers. It is also false for text values, even if the text itself appears to be a date or time.

Function IsReference

IsReference(X)

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 IsList

New to Analytica 6.5

Function IsList(x)

IsList(x) returns true when «x» is a list. It is false when «x» is a scalar or a non-list array.

Note that when the result of a Definition is a list, the list is promoted to be a self-index, at which point the value is an array rather than a list. Also, even though an index is defined using a list, the index value has been promoted to be a self-index, so will no longer be labelled as a list. Hence, this function is really only of use with local values.

Note that IsList is different from the other IsXXXX functions (other than IsNull) in that it does not array abstract. Instead of applying to each cell, it applies to the entire value.

Examples:

  • IsList( ['one','two']) --> True
  • IsList( Time ) --> False
  • Local x:='a'..'z' Do IsList(x) --> True
  • LocalIndex J:='a'..'z' Do IsList( J) --> False

Function IsNull

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 functions (other than IsList) in that it does not array abstract. Instead of applying to each cell, it applies to the entire value.

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)

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. When «shallow» is true, a less detailed type description is given. In many cases, TypeOf exposes details of the internal representation being used; hence, it is preferable to make use of the IsXXX() functions when possible.

When X is: TypeOf(X) returns: TypeOf(X, shallow: true) returns:
A real number stored internally in IEEE 754 double binary float format "Number" "Number"
An integer value stored internally as a 64-bit signed integer "Integer" "Number"
A real-value stored internally in a fixed-point real number format "FixedPoint" "Number"
A date/time numeric value "DateTime" "DateTime"
A complex (imaginary) number "ComplexNumber" "ComplexNumber"
A textual value "Text" "Text"
Null "Null" "Null"
A Linear optimization Program (returned by DefineOptimization) "LP" "Custom"
A Quadratic optimization Program with linear constraints (returned by DefineOptimization) "QP" "Custom"
A Quadratically Constrained optimization Program (returned by DefineOptimization) "QCP" "Custom"
A Non-Linear optimization Program (returned by DefineOptimization) "NLP" "Custom"
An ODBC Record Set object "RecordSet" "Custom"
A parsed expression where the outermost operation is an operator "Expression" "Expression"
A parsed expression where the outermost operation is a function call "FunctionCall" "FunctionCall"
An in-memory binary data term ("blob") "BinaryData" "BinaryData"
An image (e.g., from a Pict attribute) "«Picture(PNG)»" "Custom"
A Handle to an object with the class «className» "«className»", one of:

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

"Object"
A Reference "Reference" "Reference"
The data from an input or output attribute "ObjectSet" "ObjectSet"

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).

See Also

Comments


You are not allowed to post comments.