Value Types
Glich supports the following value types.
- String - A sequence of unicode (UTF-8) characters.
- Float - A floating point number, includes ±inf (infinity) and nan (not a number).
- Number - An integer number, can hold a value in the approximately range of ±1019.
- Field - An integer number in the range of ±2147483644, ±infinity and an undefined value '?'.
- Range - One or more consecutive fields.
- RList - A well-ordered set (list) of ranges. Includes the empty set.
- Boolean - The boolean value true or false.
- Object - A named object and a collection of values and functions.
- Blob - A block of binary data. Can be used for binary files such as images.
- Error - If an error occurs during an expression, an error value is created.
- Null - A value which has no defined content.
String
A string is sequence of unicode (UTF-8) characters. It is written by enclosing the text in double quotes '"'. If a double quote is required in the text, use two double quotes together. For example, the value "Say ""Hello""" would print as Say "Hello".
Float
A floating point number.
A float may hold the following special values.
Keyword | Meaning |
---|---|
inf | Infinity. Can be preceded by a plus '+' or minus '-' sign. |
nan | Not a number. |
Any operation with nan results in nan, with the exception of equal = and not equal <>.
float_type is also part of the numeric_type and any_numeric_type groups.
Number
A number is a 64 bit signed integer value.
number_type is also part of the integer_type, numeric_type and any_numeric_type groups.
Field
A field is a 32 bit signed integer value with some fixed values. It is used to form integer ranges and sets. It can be used with the set operands: complement '!', union '|', intersection '&', symmetric difference '^' and relative compliment '\'.
A field may hold the following special values.
Keyword | Meaning |
---|---|
infinite | Can be preceded by a plus '+' or minus '-' sign. |
? | An unknown or indeterminate value. |
field_type is also part of the set_type, integer_type, numeric_type and any_numeric_type groups.
Range
A range is expressed as two field values which denote the first and last values of an inclusive, continuous list. Both values may be the same, which implies a list of one value. A range is written using the '..' operator. Note, (a..b) is identical to (b..a). When a range is output as a string it is always written with the lower value first.
The infinity value is permitted in a range but not the '?' value.
A field may be promoted to a range with the upper and lower values equal.
A range may only be demoted to a field if both values are equal.
range_type is also part of the set_type, combined_type and any_numeric_type groups.
Rlist
An rlist is a list of ranges. The list may contain zero or more ranges. If the rlist has more than one range, it is written using the union '|' operator between ranges. When an rlist is output, it is always written as a well ordered list.
A well ordered list can be described as when, ranges are always shown with the lowest value first, multiple ranges do not overlap or abut one another and are in ascending order.
The rlist may hold the special value keyword 'empty', meaning it is the empty or null set.
A range may be promoted to an rlist with a single range.
An rlist may only be demoted to a range if, after conversion to a well ordered list, it contains a single range.
rlist_type is also part of the set_type, combined_type and any_numeric_type groups.
Boolean
A boolean value holds one of the two keywords 'true' or 'false'.
Object
An object value holds a collection of other values. It has to be defined and given a code first. After its definition it can written by enclosing the values in curly brackets, starting with the objects code name.
The language contains one built-in general purpose object that does not need to be defined before use. This is documented here.
Blob
Can be used for binary data, as listed below.
Blob Type | Description |
---|---|
unknown | Unknown binary data |
file | Represents any binary file |
jpeg, png | Image data. |
mp3 | Audio data. |
mp4 | Video data. |
Currently, this type can only be used with the function @load:blob and command save:blob.
When a string description of a blob is required, it is given in the form
blob:type:size
. For example
blob:png:1999.
Error
An error value is created whenever an operation is carried which has undefined results. When written out, the value should print text that describes where and why the error was created.
Null
A null value holds the keyword 'null'.
Only the equal '=' and not equal '<>' operators may be used with null values. The equals operator returns 'true' if both values are null and 'false' otherwise. Any other operation with null is undefined and results in an error value.
Null values can be used as place-holder values within an object value.
Summary of Types
string | string_type | ||||
float | float_type | numeric_type | any_numeric_type | ||
number | number_type | integer_type | |||
field | field_type | set_type | |||
range | range_type | combined_type | |||
rlist | rlist_type | ||||
boolean | bool_type | ||||
object | object_type | named_object_type | |||
blob | blob_type | ||||
error | error_type | ||||
null | null_type |
Automatic Type Conversions
When an operation expects two numeric types then, if both types are the same, this will be the type of the output. If the types differ, one of the types will attempt to be converted as follows.
If either type is a float, the other type will be converted to a float.
If the types are a number and a field, in either order, the number is converted to a field if possible. If the conversion would causes an overflow, it is converted to the unknown ? value.
Set types are automatically promoted or demoted as required to suit the operation. If a demotion is required but not possible then an error type is returned. Promotions are always possible.
Any other operation with unmatched types will return an error type.