Language Reference/Built-in entities/Domains
any | Universal term type |
char | Unicode character (16-bit) |
string | UTF-16 zero-terminated string |
string8 | Zero-terminated 8-bit string typically in UTF-8 encoding |
symbol | Interned UTF-16 string (global symbol table) |
binary | Byte sequence (non-scanned) |
binaryNonAtomic | Byte sequence (GC-scanned; may contain pointers) |
integer | 32-bit signed integer |
integer64 | 64-bit signed integer |
integerNative | Platform-sized signed integer (32/64-bit) |
unsigned | 32-bit unsigned integer |
unsigned64 | 64-bit unsigned integer |
unsignedNative | Platform-sized unsigned integer (32/64-bit) |
real | Floating-point number (64-bit) |
real32 | Floating-point number (32-bit) |
pointer | Pointer value |
pointerTo | Pointer to a value of a given type |
handle | Operating system handle (e.g., Windows) |
boolean | Boolean values |
factDB | Descriptor of a named internal database |
compareResult | Result of a comparison |
any
Universal term type.
any
Values of this domain can hold any term. Such a value contains a reference to the type library of the term and the term itself.
char
Unicode character.
char
Values of this domain are Unicode characters implemented as two unsigned bytes.
Only assignment and comparison (lexicographical) are defined. The image of a character has the following syntax:
Char_image : ' Char_value ' Char_value : Letter Digit Graphical_symbol Escape_seq Escape_seq: \t \n \r \\ \' \" \u<HHHH>
In the syntax above HHHH corresponds to four hexadecimal digits. The backslash and single quote can only be represented by escape sequences.
compareResult
The result domain for comparisons (e.g., compare/2->).
domains compareResult = less; equal; greater.
string
UTF-16 strings.
string
A string is a pointer to a zero-terminated sequence of UTF-16 code units. Elements are 16-bit values; certain characters are encoded using surrogate pairs. Strings are immutable.
In source code a string literal is one or more parts surrounded by double quotes:
StringLiteral: StringLiteralPart-list
StringLiteralPart : @" AnyCharacter-list-opt " " CharacterValue-list-opt "
Parts starting with @ do not use escape sequences; parts without @ use the following escapes:
- \\ representing \
- \t representing a tab character
- \n representing a newline character
- \r representing a carriage return
- \' representing a single quote
- \" representing a double quote
- \u followed by exactly four HexadecimalDigit values representing the Unicode character
Double quotes in strings must be written using the escape sequence (single quotes may be written directly or escaped).
string8
A built-in domain whose elements are sequences of one-byte characters (bytes). Implemented as a pointer to a zero-terminated array of bytes.
Literals. The same string literal syntax (`"..."`) can be used both as a string literal and as a string8 literal, depending on context:
- When a string8 value is expected, the literal is compiled as UTF-8 bytes with a trailing zero
- When a string value is expected, the literal is compiled as UTF-16 code units with a trailing zero
If the context is ambiguous, disambiguate by using a typed context (e.g., a predicate parameter of type string8) or by explicit conversion.
predicates use8 : (string8 S8). use16 : (string S). clauses demo() :- use8("Hello"), % literal used as string8 (UTF-8) use16("Hello"). % the same literal used as string (UTF-16)
symbol
UTF-16 strings with the same representation as string, but also stored in a global symbol table.
symbol
A symbol is interned in a global symbol table; identical symbols share the same pointer value. Symbols are never reclaimed, so they should not be used for large, short-lived text.
symbol is a subtype of string, so a symbol can be used wherever a string is expected. The opposite is not automatic; to obtain a symbol from a string, explicitly convert to the symbol domain (or a subtype).
Equality is efficient for symbol values (pointer equality). Other comparisons behave like the corresponding string operations.
binary
Sequence of bytes.
binary
Used for holding binary data. A value is a pointer to the byte sequence that represents the contents of the binary term.
The length of a binary term is stored in the four bytes immediately preceding the sequence:
TotalNumberOfBytesOccupiedByBinary = ByteLen + 4
where ByteLen is the length of the sequence and 4 is the size field.
Only assignment and comparison are defined.
Two binaries are compared as follows:
- If sizes differ, the larger size is greater
- Otherwise, compare bytes (as unsigned) until a difference is found; equal if sizes match and all bytes are equal
The text syntax for binary images is determined by Binary:
Binary : $ [ Byte_value-comma-sep-list-opt ] Byte_value : Expression
Each expression must be computable at compile time and have a value in the range 0.. 255.
binaryNonAtomic
Sequence of bytes.
binaryNonAtomic
Same as binary, but may contain pointers and is scanned by the garbage collector.
integer
32-bit signed integer.
integer
Values occupy 4 bytes. Arithmetic (+, -, /, *, ^), comparison, assignment, div/2->, mod/2->, quot/2->, and rem/2-> are defined.
Range: -2147483648 .. 2147483647.
Literals follow Integer:
Integer : Add_operation-opt 0o Oct_number Add_operation-opt Dec_number Add_operation-opt 0x Hex_number Add_operation : + - Oct_number : Oct_digit-list Oct_digit : one of 0 1 2 3 4 5 6 7 Dec_number : Dec_digit-list Dec_digit : one of Oct_digit 8 9 Hex_number : Hex_digit-list Hex_digit : one of Dec_digit a b c d e f A B C D E F
integer64
64-bit signed integer.
integer64
Values occupy 8 bytes.
Range: -2^63 = -9223372036854775808 .. 2^63-1 = 9223372036854775807.
Literals use the same syntax as Integer. The available operations mirror those for Integer.
integerNative
Platform-sized signed integer (32-bit in 32-bit programs; 64-bit in 64-bit programs).
integerNative
unsigned
32-bit unsigned integer.
unsigned
Values occupy 4 bytes. Arithmetic (+, -, /, *, ^), comparison, assignment, div/2->, mod/2->, rem/2->, and quot/2-> are defined.
Range: 0 .. 4294967295.
Literals use the same syntax as integer numbers. A leading minus (UnaryMinus) is not allowed for an unsigned literal.
unsigned64
64-bit unsigned integer.
unsigned64
Values occupy 8 bytes.
Range: 0 .. 2^64-1 = 18,446,744,073,709,551,615.
Literals use the same syntax as integer64 numbers. A leading minus (UnaryMinus) is not allowed for an unsigned64 literal.
Operations mirror those for Unsigned.
unsignedNative
Platform-sized unsigned integer (32-bit in 32-bit programs; 64-bit in 64-bit programs).
unsignedNative
real
Floating-point number.
real
Values occupy 8 bytes. All arithmetic, comparison, and assignment operations are defined.
Range: approximately -1.7e+308 .. 1.7e+308. Integral values are implicitly converted to real when needed.
Floating-point literals follow Real:
Real : Add_operation-opt Fraction Exponent-opt Fraction : Dec_number Fractional_part-opt Fractional_part : . Dec_number Exponent : Exp Add_operation-opt Dec_number Exp : e E Add_operation : + - Dec_number : Dec_digit-list Dec_digit : one of 0 1 2 3 4 5 6 7 8 9
real32
Floating-point number.
real32
Values occupy 4 bytes. All arithmetic, comparison, and assignment operations are defined.
Range: approximately -3.4e+38 .. 3.4e+38.
The syntax of real32 literals is the same as for real literals.
pointer
A pointer to a memory address.
pointer
Corresponds directly to memory addresses. Only equality comparison is defined. There is a built-in null constant for this type.
pointerTo
pointerTo{Type} represents a pointer to a value of type Type. Conceptually (it is built-in), it can be viewed as:
domains pointerTo{Type} = pointerTo(Type Value).
handle
Used for Windows API calls. Values have the same size as a pointer (4 bytes on 32-bit, 8 bytes on 64-bit platforms).
No operations are defined for this domain, and values cannot be converted to/from other domains (except via uncheckedConvert).
There are built-in constants: nullHandle and invalidHandle.
boolean
Boolean values.
boolean
This domain is provided for convenience and is treated as a normal compound domain:
domains boolean = false; true.
factDB
Descriptors of named internal databases.
factDB
This domain has the following hidden meta-declaration:
domains factDB = struct @factdb( named_internal_database_domain, object ).
All user-defined names of facts sections are constants of this domain. The compiler automatically builds the corresponding compound terms when needed. At runtime, the first field holds the address of the corresponding domain descriptor, and the second holds either zero (for class facts sections) or a pointer to an object (e.g., This for object facts sections).