Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: Type Conversion Up: Predefined Functions and Variables Previous: Predefined Functions and Variables


Type Identification

Glish provides the following functions for identifying the type of a value:

is_boolean(x)
returns true (T) if x's type is boolean and false (F) otherwise. The following analogous functions are available for identifying other types:
    is_byte(x)
    is_short(x)
    is_integer(x)
    is_float(x)
    is_double(x)
    is_complex(x)
    is_dcomplex(x)
    is_string(x)
    is_regex(x)
    is_record(x)
    is_function(x)
    is_agent(x)
    is_file(x)

is_numeric(x)
returns T if x's type is numeric (boolean, byte, short, integer, float, double, complex or dcomplex), F otherwise.

is_const(x)
returns T if x is const (see § 3.9), i.e. it cannot be modified and cannot be reassigned. Otherwise is_const returns F.

is_modifiable(x)
returns T if x can be modified, otherwise F is returned. While x may not be modifiable, x still might be reassignable (see § 3.9).

is_nan(x)
returns T if x is not a number as defined in the IEEE floating point standards, e.g. is_nan(0/0) returns T.

is_fail(x)
returns T if x is a fail value otherwise it returns F. This function is unique in that passing a fail value into it doesn't automatically cause it to fail, as is the case with any other function. (See § 9.1, page [*] for more information.)

type_name(x)
returns a string scalar identifying the type of x. For example,
    type_name(5)
returns "integer" and
    type_name(func (x) x+1)
returns "function". The names of the various types are:
    "boolean"
    "byte"
    "short"
    "integer"
    "float"
    "double"
    "complex"
    "dcomplex"
    "string"
    "regex"
    "record"
    "function"
    "agent"
    "fail"
    "file"

The name of a reference type is the concatenation of the string "ref" followed by the name of the referred-to type. For example,

    type_name(ref "hi")
yields 'ref string' as a scalar value.

full_type_name(x)
returns a more detailed description of x's type.

If the value is a vector with more than one element then the function reports its size and its type:

    full_type_name(1:10)
yields 'integer [10]'.

If the value is a record then the function identifies each field's name and type (recursively, if one of the fields is itself a record):

    full_type_name([a=1, b="how are you?", c=2:5])
yields
    'record [a=integer, b=string [3], c=integer [4]]'

If the value is a reference then the function returns only its referred-to type:

    full_type_name(ref 5)
returns 'integer'.

field_names(x)
returns a string vector listing all of the fields in x. For example,
    field_names([a=1, b="how are you?", c=2:5])
yields "a b c".

If x is not a record than an error message is printed and F is returned.

has_field(x,field)
returns T if x is a record and contains a field with the given name, F otherwise.


next up previous contents index
Next: Type Conversion Up: Predefined Functions and Variables Previous: Predefined Functions and Variables   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15