Gamma: Version 4.0
Prev |  | Next

# Data Types and Predicates

-- testing for data types.

##

Unlike many languages, just about every expression in Gamma is a data type. This gives the flexibility to manipulate functions, arrays, lists, classes, instances and so on as if they were data.

The following data types are defined in Gamma. Beside each data type is the name of a function which can be used to test an expression for that type. These functions are called predicates, and will return `t` if the test is true (the expression is that data type), or `nil` if it is false.

Table 1. Data Types and Related Predicates

Type | Predicate | Comments
--- | --- | ---
alist | `alist_p` | An association list. See `assoc`.
array | `array_p` | See `array` and Lists and Arrays.
autotrace | `autotrace_p` |
breakpoint | `breakpoint_p` |
buffer | `buffer_p` | See `buffer`.
builtin | `builtin_p` |
class | `class_p` | See `class`.
cons | `cons_p` | See `cons` and `list`.
constant | `constant_p` | Constants can be assigned or defined. See `defvar` and `::=`.
destroyed instance | `destroyed_p` | See `new` `(instance)`.
file | `file_p` | See `open` and `open_string`.
fixed-point real | `fixed_point_p` | See Numeric Types.
function | `function_p` | See `function`.
instance | `instance_p` | See `new` `(instance)`.
integer | `int_p`, `long_p` | See Literals.
list | `list_p` | See `list` and Lists and Arrays.
macro | `macro_p` | See `macro`.
method | `method_p` (obsolete, always returns nil) | See `method`.
nil | `nil_p` | See nil.
number | `number_p` | Integer and floating point values are both considered numbers. See Literals.
real | `real_p` | See Literals.
registered | `registered_p` | See `register_point`.
string | `string_p` | See Literals and `string`.
sym-alist | `sym_alist_p` | A symbol-indexed association list. See `assoc`.
symbol | `symbol_p` | See Literals.
t | `true_p` | See t.
task descriptor | none | See `locate_task`.
undefined | `undefined_p` | See `undefined_p`.
undefined symbol | `undefined_symbol_p` | See `undefined_symbol_p`.

## Predicates

Predicates are used to test a Gamma object for a given type, as listed. If a Gamma object is of that type, the predicate will return the value `t`.

### Syntax

        alist_p (s_exp)
        array_p (s_exp)
        autotrace_p (s_exp)
        breakpoint_p (s_exp)
        buffer_p (s_exp)
        builtin_p (s_exp)
        class_p (s_exp)
        cons_p (s_exp)
        constant_p (s_exp)
        destroyed_p (s_exp)
        file_p (s_exp)
        fixed_point_p (s_exp)
        function_p (s_exp)
        instance_p (s_exp)
        int_p (s_exp)
        list_p (s_exp)
        long_p (s_exp)
        macro_p (s_exp)
        method_p (s_exp)
        nil_p (s_exp)
        number_p (s_exp)
        real_p (s_exp)
        registered_p (s_exp)
        string_p (s_exp)
        sym_alist_p (s_exp)
        symbol_p (s_exp)
        true_p (s_exp)
        none_p (s_exp)
        undefined_p (s_exp)
        undefined_symbol_p (s_exp)

### Arguments

any expression

### Returns

`t` or `nil.`

### Example

Here is an example for the predicate `function_p`. All the other predicates work in a similar way.

        Gamma> function_p(div);
        t
        Gamma> function_p(strcmp);
        t
        Gamma> function_p(5);
        nil
        Gamma>

See the PID Controller Class section of the PID Emulator chapter, or the GTK: Sending Queries section or the Photon: Sending Queries section of the History Functions chapter in the Cogent Tools Demo and Tutorials book for examples of the `number_p` function used in context.

Prev | Home | Next
Symbols and Literals | Up | `undefined_p`, `undefined_symbol_p`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.