next up previous contents
Next: Iteration and Recursion Up: Structured Types Previous: Selection on Data Structures

The Types of Structured Types

You can test whether a name has been assigned to a procedure as follows:

> example := proc( )                  # an empty procedure
> end:
> type(example, procedure);
A valid Darwin name has type name.
> type(example, name);
> type(a_valid_Darwin_name, name);
An unevaluated procedure call has type uneval. The spirit of uneval comes from the fact that objects of this type ``look like'' procedure calls. The difference between objects of type procedure and type uneval is that the former evaluates while the latter does not.

Recall that there are two ways a procedure call will remain unevaluated in Darwin: either the procedure name is wrapped in a noeval command or the name is undefined in the environment.

> z := noeval(example());
> type(z, uneval);
> type(any_undefined_name(), uneval);

An object has type structure if it is either a built-in Darwin structured type or it is of type uneval.

> type(Gene, structure);       # the built-in structured type to hold a gene
> type(Tree, structure);       # the built-in structured type to hold a tree
> type(MultiAlign, structure); # the built-in structured type to hold a multiple alignment

> x := new_type();             # x is a variable of a new user defined type
> type( x, uneval );           # therefore it has type uneval
> type( x, structure );        # and type structure

If we create a new structured type such as NewStruct and a variable of this type

> x := NewStruct(a, 5, {1, 2, 3});
the type of x is only the general class noeval. We can explicitly make NewStruct a structured type recognized by Darwin by assigning the type name NewStruct the specification as an unevaluated function of type anything.
> NewStruct_type := specuneval(anything, NewStruct);
Now we may test whether the type of x is NewStruct.
> type(x, NewStruct);
We could encode stricter type checking into NewStruct by replacing the anything declaration in the specuneval command with a sequence of types.
> NewStruct_type := specuneval(string, integer, set, NewStruct);


next up previous contents
Next: Iteration and Recursion Up: Structured Types Previous: Selection on Data Structures
Gaston Gonnet
1998-09-15