Cind language documentation

Operations on types

There are four binary operators on types: ==, !=, >> and >>=. Each operation returns boolean value.
First two operators, == and !=, simply checks whenever given types are equal or not.

Next operators, >> and >>=, checks if the type in their second argument lays on the inheritance chain of the type from the first argument. The difference between them, is that checks will be performed with or without the first type in the chain. When it is unable to determine the type of the object or when inheritance chain is not defined by extending from some other type, then those operations will return false (for inheritance chain see Class inheritance).

Examples:

float == int int != int[] a.b.c >>= d.e.f

It is allowed to use type word before the type name, to prevent the compiler not to treat type name as some other expression. Example:

type x != int

Instruction typeof

Instruction typeof returns type of given object, and can be used as an argument to the type operators and switch instructions.
Example:

typeof(x) == int

In conjunction with operators >> or >>= instruction typeof makes a special case, allowing to search type in inheritance chain of already created object, which allows to walk on chain connected with direct indication (with over method).
Example:

typeof(x) >>= a.b.c

In known cases a typeof instruction will be resolved by the compiler, as a type of a given object or expression or as a type assigned to a given variable.

Instruction typeof can be also used inside type cast operator. For example:

x = (typeof(y))z;

is converting value z to the type of the value in the variable y.
For type cast operator see Type conversion.

Type unknown

When it is unable to determine the type of an object, for example, when it comes from the other environment or it is an external object (see External objects), then instruction typeof will return unknown type which is a special case of the type.

Examples of use:

typeof(x) != unknown switch typeof(y) { case int[]: ... unknown: ... // case for unknown type default: ... }

Cind programming language 1.0.4

 

Advertisements