1.177 class type

A type object defines which data entities are accepted as filler for an instance variable or arguments to a method. Type objects are part of the definition of both methods and variables.

Types are normally specified using a name. The type<-convert method translates type-names into (reusable) type objects. See type<-convert for the type syntax.

If a type is used to specify the arguments to a method, it can also specify the name of the argument. See type<-argument_name. Argument names are used for documentation purposes as well as to allow for the specification of arguments by name rather than by position. See class := for details.

Bugs:

Currently, the semantics of a type is determined by the type<->kind attribute and no new kinds may be introduced.

Type objects have no protection against changes to them, but they may not be changed, except as part of their definition process.

See also
- object->_check
- class variable
- class send_method
- class get_method

1.177.1 Instance variables

type <- argument_name: name*
Name of the argument specified. If @nil, no argument name is associated. Types used to specify an argument name have type<-kind: alias. type<-context contains the real type specification.
type <- context: any
The context field is provided with the C-functions type<-translate_function and type<-validate_function. The contents of this field is determined by these functions, and therefore by the type<->kind attribute.
See also
type-kind
type <- fullname: name
The name used to define this type. See type<-convert.
type <- kind: name
The type<-kind attribute determines the -validate_function and -translate_function pointers and thus interpretation of the context attribute. Its values are (between brackets the the syntax construct; see also type<-convert).

Objects (instances of classes):

type <- supers: chain*
Chain of type objects that act as alternatives. Used by type->validate and type<-translate after its own validation or translation fails.
See also
type<-check
type-translate_function: alien:Func
@see type-kind @see type<-translate
type-validate_function: alien:SendFunc
@see type-kind
type <- vector: bool
Indicates the type should be interpreted as a varargs type by a method. This implies any number of datums of this type is allowed.

1.177.2 Send methods

type ->initialise: name=name, kind=[name], context=[any], supers=[chain*]
Create a new type object. Name is the name of the type and should not already exist (see also type<-lookup). After creation, the type is object->protect’ed and a mapping from the type type<-fullname to the type object is added to the hash_table object @types. The arguments are:

type ->validate: unchecked, [object]*
Validate that the argument can be accepted as satisfying this type. First activates the type<-validate_function. When this fails, it requests the super-types to validate the argument.
See also
- type<-check
- type<-translate

1.177.3 Get methods

type <-check: value=unchecked, context=[object]* -> unchecked
The type<-check method is the normal way to activate a type. The first argument is the object to be checked. The second is the receiver that requests the conversion. The latter is currently used only for the type<->kind member.

Types are normally referred to by their type<-name rather than by their reference. For this reason type checking and conversion is also accessible through pce<-convert. The following two lines are identical:

?- get(@pce, convert, '34', int, Int).
?- get(type(int), check, '34', Int).

First, type->validate is activated. If this fails, type<-translate is activated and the result thereof is returned.

See also
- class function
- pce<-convert
- text_item-type
- type->validate
- type<-translate
- type-supers
type <-convert: name -> type
Convert a name into a type. This is the normal way to define or use a type. The conversion syntax is (informally) defined below:
<Type>      ::= <KindType>
                      | <SingleType> '...'		% Methods: Varargs

<KindType>  ::= 'alien:'<C-type>        % Alien (C) types
                          | 'member:'<Single>		% Members

<Single>    ::= <PrimType>
                          | <Single>'|'<Single>		% Disjunction
                          | '['Single']'			% May be @default
                          | <Single>'*'				% May be @nil

<PrimType>  ::= <PredefinedType>        % any defined type
                          | {<Name>',' ...}			% name_of
                          | <int>'..'<int>			% integer range
                          | <real>'..'<real>		% real range
                          | <ClassName>

Below are some examples:

point			Instance of class point or a subclass
int		    	integer
[name]			A name or @default
graphical*		A graphical object or @nil
int|point		integer or point
{left,right}	either the name 'left' or 'right'

  1. .100 integer in the range 0 ... 100 (including) name|function Accepts a name or a function object.
    See also
    - !bad_type_syntax
    - pce<-convert
    - type->initialise
type <-copy: name -> type
Create a copy of a type with a new name. This may be used to create synonym types or extend types in ways not supported by the default conversion from a name to a type. Example:
?- get(@pce, convert, '{left,center,right}', type, X),
?- get(X, copy, format_name, _).

Creates a type format_name that accepts the names’left’,’center’or’right’.

See also
type->initialise
type <-lookup: name -> type
Lookup type in type-database @types.
type <-translate: value=unchecked, context=[object]* -> unchecked
Convert the first argument into a datum that satisfies the type. The second argument is optional context information. Both variables and methods pass the receiver through this argument. The pseudo code of this method is:
translate(Type type, Any value, Object context)
{ Activate translate_function.
  IF successful, return the translated value;
  ELSE try super-types until one succeeds and return the value
}
NOTE: Normally not activated directly, but through type<-check because the argument may not be of the requested type.
See also
- type->validate
- type<-check
- type-translate_function
type <-value_set: [object]* -> chain
Chain with values that satisfy the type object. This method is exploited by text_item<-completions to perform automatic completion.

Currently this method takes care of: