Difference between revisions of "Language Reference/Built-in entities/Domains"
m (formulation) |
SergeMukhin (talk | contribs) m (remove ()) |
||
(24 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{|{{prettytable}} | {|{{prettytable}} | ||
|- | |||
|[[#any|any]] | |||
|Universal term type. | |||
|- | |- | ||
|[[#char|char]] | |[[#char|char]] | ||
Line 20: | Line 23: | ||
|- | |- | ||
|[[#integer|integer]] | |[[#integer|integer]] | ||
| | |32 bit signed integer. | ||
|- | |- | ||
|[[#integer64|integer64]] | |[[#integer64|integer64]] | ||
| | |64 bit signed integer. | ||
|- | |||
|[[#integerNative|integerNative]] | |||
|Signed integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program). | |||
|- | |- | ||
|[[#unsigned|unsigned]] | |[[#unsigned|unsigned]] | ||
| | |32 bit unsigned integer. | ||
|- | |- | ||
|[[#unsigned64|unsigned64]] | |[[#unsigned64|unsigned64]] | ||
| | |64 bit unsigned integer. | ||
|- | |||
|[[#unsignedNative|unsignedNative]] | |||
|Unsigned integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program). | |||
|- | |- | ||
|[[#real|real]] | |[[#real|real]] | ||
Line 38: | Line 47: | ||
|- | |- | ||
|[[#pointer|pointer]] | |[[#pointer|pointer]] | ||
| | |pointer to a memory address. | ||
|- | |- | ||
|[[#handle|handle]] | |[[#handle|handle]] | ||
| | |a handle (e.g. native file and windows handles). | ||
|- | |- | ||
|[[#boolean|boolean]] | |[[#boolean|boolean]] | ||
Line 52: | Line 61: | ||
|Values of comparison result. | |Values of comparison result. | ||
|} | |} | ||
==== any ==== | |||
Universal term type. | |||
<vip>any</vip> | |||
The values of this domain are any terms. Such a value contains the reference to the term type library and a term itself. | |||
==== char ==== | ==== char ==== | ||
Line 77: | Line 94: | ||
' | ' | ||
" | " | ||
u HHHH</vipbnf> | u <HHHH></vipbnf> | ||
In the syntax above <vpbnf><HHHH></vpbnf> correspond to 4 hexadecimal digits. Also, the backslash symbol and the single quote can be represented by an escape-sequence only. | In the syntax above <vpbnf><HHHH></vpbnf> correspond to 4 hexadecimal digits. Also, the backslash symbol and the single quote can be represented by an escape-sequence only. | ||
Line 83: | Line 100: | ||
==== compareResult ==== | ==== compareResult ==== | ||
The | The result of a comparison. For instance, the built-in procedure {{lang2|Built-in entities|compare|compare/2->}} has "compareResult" as the domain of its result. | ||
<vip>domains | <vip>domains | ||
compareResult = less; equal; greater. | compareResult = less; equal; greater. | ||
Line 90: | Line 107: | ||
==== string ==== | ==== string ==== | ||
Utf-16 strings. | |||
<vip>string</vip> | <vip>string</vip> | ||
A string | A string represented as a pointer to a zero terminated sequence of characters in utf-16 encoding. Values in the sequence are 16 bits, but certain rare characters (code points) are encoded using two such values. Strings are immutable. | ||
In source code a string literal can be specified as a set of sequences of characters surrounded by the double quotes. | In source code a string literal can be specified as a set of sequences of characters surrounded by the double quotes. | ||
Line 119: | Line 136: | ||
==== string8 ==== | ==== string8 ==== | ||
A | A built-in domain who's elements are sequences of (one-byte) ASCII-characters. It is implemented as a pointer to the zero terminated array of ASCII characters. Only assignment and comparison for equality (in the lexicographical sense) operations are applied to the values of this domain. Currently no literals are allowed for this domain. | ||
==== symbol ==== | ==== symbol ==== | ||
Utf-16 strings with same representation as <vp>string</vp>, but they are also stored in a global symbol table. | |||
<vip>symbol</vip> | <vip>symbol</vip> | ||
A <vp>symbol</vp> is stored in a global symbol table, and that storage guarenties that the pointer value of symbols will be the same for the same symbol. Once a <vp>symbol</vp> is put into the symbol table it is never removed again, so <vp>symbol</vp>s are never reclaimed. Their storage will live untill the program terminates. So the <vp>symbol</vp> data type should not be used for large documents, etc. | |||
The | The <vp>symbol</vp> domain is a subtype of the <vp>string</vp> domain, so a symbol can be used everywhere instead of a string. The opposite is not the case because a <vp>string</vp> will have to be found or inserted in the global symbol table to become a <vp>symbol</vp>. So to create a symbol from a string you will have to <vp>convert</vp> the string to the symbol domain (or a subtype of the <vp>symbol</vp> domain). | ||
The equality operation is very efficient for <vp>symbol</vp>s since their pointer value will be the same if the <vp>symbol</vp> is the same. I.e. there is no need to compare the actual characters to determine equality. | |||
Other comparison operations (less than, case insensitive comparison, etc) are the same as for <vp>string</vp> in fact all other operations on <vp>symbol</vp> is simply carried out by the corresponding string operations. | |||
==== binary ==== | ==== binary ==== | ||
Sequence of | Sequence of bytes. | ||
<vip>binary</vip> | <vip>binary</vip> | ||
Line 165: | Line 184: | ||
==== binaryNonAtomic ==== | ==== binaryNonAtomic ==== | ||
Sequence of | Sequence of bytes. | ||
<vip>binaryNonAtomic</vip> | <vip>binaryNonAtomic</vip> | ||
Same as [[#binary|binary]], but can contain | Same as [[#binary|binary]], but can contain pointers because it is scanned by the garbage collector. | ||
==== integer ==== | ==== integer ==== | ||
32 bit signed integer. | |||
<vip>integer</vip> | <vip>integer</vip> | ||
Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, | Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, {{lang2|Built-in entities|Operators|div/2->}}, {{lang2|Built-in entities|Operators|mod/2->}}, {{lang2|Built-in entities|Operators|quot/2->}}, and {{lang2|Built-in entities|Operators|rem/2->}} operations are applied to values of this domain. | ||
The permitted number range is from <vp>-2147483648</vp> to <vp>2147483647</vp>. | The permitted number range is from <vp>-2147483648</vp> to <vp>2147483647</vp>. | ||
Line 205: | Line 224: | ||
==== integer64 ==== | ==== integer64 ==== | ||
64 bit signed integers. | |||
<vip>integer64</vip> | <vip>integer64</vip> | ||
Line 211: | Line 230: | ||
Values of this domain occupy 8 bytes. | Values of this domain occupy 8 bytes. | ||
The permitted number range is from <vp>-2^63 = - | The permitted number range is from <vp>-2^63 = -9223372036854775808</vp> to <vp>2^63-1 = 9223372036854775807</vp>. | ||
The syntax for <vp>integer64</vp> literal is the same as <vpbnf><Integer></vpbnf> rule. | The syntax for <vp>integer64</vp> literal is the same as <vpbnf><Integer></vpbnf> rule. | ||
The set of operations for <vp>integer64</vp> is similar to the one for <vpbnf><Integer></vpbnf>. | The set of operations for <vp>integer64</vp> is similar to the one for <vpbnf><Integer></vpbnf>. | ||
==== integerNative ==== | |||
Signed integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program). | |||
<vip>integerNative</vip> | |||
==== unsigned ==== | ==== unsigned ==== | ||
32 bit unsigned integer. | |||
<vip>unsigned</vip> | <vip>unsigned</vip> | ||
Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, {{lang2|Built-in entities| | Values of this domain occupy 4 bytes. Arithmetic operations (<vp>+</vp>, <vp>-</vp>, <vp>/</vp>, <vp>*</vp>, <vp>^</vp>), comparison, assignment, {{lang2|Built-in entities|Operators|div/2->}}, {{lang2|Built-in entities|Operators|mod/2->}}, {{lang2|Built-in entities|Operators|rem/2->}}, and {{lang2|Built-in entities|Operators|quot/2->}} operations are applied to values of this domain. | ||
The permitted number range is from <vp>0</vp> to <vp>4294967295</vp>. | The permitted number range is from <vp>0</vp> to <vp>4294967295</vp>. | ||
Line 231: | Line 256: | ||
==== unsigned64 ==== | ==== unsigned64 ==== | ||
64 bit unsigned integer. | |||
<vip>unsigned64</vip> | <vip>unsigned64</vip> | ||
Line 242: | Line 267: | ||
The set of operations for <vp>unsigned64</vp> is similar to the one for <vpbnf><Unsigned></vpbnf>. | The set of operations for <vp>unsigned64</vp> is similar to the one for <vpbnf><Unsigned></vpbnf>. | ||
==== unsignedNative ==== | |||
Unsigned integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program). | |||
<vip>unsignedNative</vip> | |||
==== real ==== | ==== real ==== | ||
Line 293: | Line 324: | ||
A pointer directly corresponds to memory addresses. Only the equality operation can be applied to the values of this domain. There is a built-in '''null''' constant for this type | A pointer directly corresponds to memory addresses. Only the equality operation can be applied to the values of this domain. There is a built-in '''null''' constant for this type | ||
==== pointerTo ==== | |||
<vp>pointerTo{Type}</vp> represents a pointer to a value of type <vp>Type</vp>. It's definition is like this (but it is built-in): | |||
<vip>domains | |||
pointerTo{Type} = pointerTo(Type Value).</vip> | |||
==== handle ==== | ==== handle ==== | ||
A handle is used for Windows API function call. Values of this domain | A handle is used for Windows API function call. Values of this domain has the same size as a pointer (i.e. 4 on 32bit platfor and 8 on 64bit platform). | ||
There are no operations for this domain and cannot be converted (except uncheckedConvert) to/from other domains. | There are no operations for this domain and cannot be converted (except uncheckedConvert) to/from other domains. | ||
Line 311: | Line 349: | ||
<vip>domains | <vip>domains | ||
boolean = false | boolean = false; true.</vip> | ||
==== factDB ==== | ==== factDB ==== | ||
Line 325: | Line 363: | ||
All user-defined names of facts sections are the constants of this domain. The compiler automatically builds the corresponding compound terms from such constants whenever it's in need. At the runtime the 1st field of this structure contains the address of the corresponding domain descriptor and the 2nd field contains either zero (for class facts sections) or pointer to an object (i.e. <vp>This</vp>, for object facts sections). | All user-defined names of facts sections are the constants of this domain. The compiler automatically builds the corresponding compound terms from such constants whenever it's in need. At the runtime the 1st field of this structure contains the address of the corresponding domain descriptor and the 2nd field contains either zero (for class facts sections) or pointer to an object (i.e. <vp>This</vp>, for object facts sections). | ||
<noinclude>{{LanguageReferenceSubarticle|Built-in entities/Domains}}</noinclude> | |||
<noinclude> |
Latest revision as of 13:33, 12 November 2023
any | Universal term type. |
char | Wide (two-bytes) character. |
string | Wide zero-terminated sequence of wide characters. |
string8 | Zero-terminated sequence of ASCII (one-byte) characters. |
symbol | Wide zero-terminated sequence of wide characters. |
binary | Sequence of bytes. |
binaryNonAtomic | Sequence of bytes. |
integer | 32 bit signed integer. |
integer64 | 64 bit signed integer. |
integerNative | Signed integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program). |
unsigned | 32 bit unsigned integer. |
unsigned64 | 64 bit unsigned integer. |
unsignedNative | Unsigned integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program). |
real | Float-pointing number. |
real32 | Float-pointing number. |
pointer | pointer to a memory address. |
handle | a handle (e.g. native file and windows handles). |
boolean | Boolean values. |
factDB | Descriptors of named internal databases. |
compareResult | Values of comparison result. |
any
Universal term type.
any
The values of this domain are any terms. Such a value contains the reference to the term type library and a term itself.
char
Wide character.
char
The values of this domain are UNICODE characters. Implemented as 2 unsigned bytes.
Only assignment and comparison (in the lexicographical sense) operations are applied to the values of this domain. 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 correspond to 4 hexadecimal digits. Also, the backslash symbol and the single quote can be represented by an escape-sequence only.
compareResult
The result of a comparison. For instance, the built-in procedure compare/2-> has "compareResult" as the domain of its result.
domains compareResult = less; equal; greater.
string
Utf-16 strings.
string
A string represented as a pointer to a zero terminated sequence of characters in utf-16 encoding. Values in the sequence are 16 bits, but certain rare characters (code points) are encoded using two such values. Strings are immutable.
In source code a string literal can be specified as a set of sequences of characters surrounded by the double quotes.
StringLiteral: StringLiteralPart-list
StringLiteralPart : @" AnyCharacter-list-opt " " CharacterValue-list-opt "
A string literal consists of one or more StringLiteralPart's, which are concatenated. StringLiteralPart's starting with @ does not use escape sequences, whereas StringLiteralPart's without @ uses the following escape sequences:
- \\ representing \
- \t representing Tab-character
- \n representing newline-character
- \r representing carriage return
- \' representing single quote
- \" representing double quote
- \u followed by exactly four HexadecimalDigit's representing the Unicode character corresponding to the digits.
The double quotes in the string can be represented by the escape-sequence only (the single quote can be represented both with an escape-sequence and a graphical symbol).
string8
A built-in domain who's elements are sequences of (one-byte) ASCII-characters. It is implemented as a pointer to the zero terminated array of ASCII characters. Only assignment and comparison for equality (in the lexicographical sense) operations are applied to the values of this domain. Currently no literals are allowed for this domain.
symbol
Utf-16 strings with same representation as string, but they are also stored in a global symbol table.
symbol
A symbol is stored in a global symbol table, and that storage guarenties that the pointer value of symbols will be the same for the same symbol. Once a symbol is put into the symbol table it is never removed again, so symbols are never reclaimed. Their storage will live untill the program terminates. So the symbol data type should not be used for large documents, etc.
The symbol domain is a subtype of the string domain, so a symbol can be used everywhere instead of a string. The opposite is not the case because a string will have to be found or inserted in the global symbol table to become a symbol. So to create a symbol from a string you will have to convert the string to the symbol domain (or a subtype of the symbol domain).
The equality operation is very efficient for symbols since their pointer value will be the same if the symbol is the same. I.e. there is no need to compare the actual characters to determine equality.
Other comparison operations (less than, case insensitive comparison, etc) are the same as for string in fact all other operations on symbol is simply carried out by the corresponding string operations.
binary
Sequence of bytes.
binary
Values of this domain are used for holding binary data. A binary value is implemented as a pointer to the sequence of bytes that represents the contents of a binary term.
The length of a binary term is situated in the 4 bytes immediately preceding this sequence of bytes. The 4 bytes contains:
TotalNumberOfBytesOccupiedByBinary = ByteLen + 4
where ByteLen - is the length of the binary term and 4 is number of bytes occupied by size field.
Only assignment and comparison operations are applied to values of binary domain.
Two binary terms are compared in the following way:
- If they are of different sizes, the bigger is considered larger.
- Otherwise, they are compared byte by byte, as unsigned values. Comparison stops when two differing bytes are found and the result of their comparison is the result of the comparison of the binary terms. Two binary terms are equal if they have the same sizes and all bytes are equal.
The text syntax for binary images is determined by the Binary rules:
Binary : $ [ Byte_value-comma-sep-list-opt ] Byte_value : Expression
Each expression should be calculate on compiling time and its value should be in the range from 0 to 255.
binaryNonAtomic
Sequence of bytes.
binaryNonAtomic
Same as binary, but can contain pointers because it is scanned by the garbage collector.
integer
32 bit signed integer.
integer
Values of this domain occupy 4 bytes. Arithmetic operations (+, -, /, *, ^), comparison, assignment, div/2->, mod/2->, quot/2->, and rem/2-> operations are applied to values of this domain.
The permitted number range is from -2147483648 to 2147483647.
The syntax for the integer literal is determined by the Integer rule:
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 integers.
integer64
Values of this domain occupy 8 bytes.
The permitted number range is from -2^63 = -9223372036854775808 to 2^63-1 = 9223372036854775807.
The syntax for integer64 literal is the same as Integer rule.
The set of operations for integer64 is similar to the one for Integer.
integerNative
Signed integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
integerNative
unsigned
32 bit unsigned integer.
unsigned
Values of this domain occupy 4 bytes. Arithmetic operations (+, -, /, *, ^), comparison, assignment, div/2->, mod/2->, rem/2->, and quot/2-> operations are applied to values of this domain.
The permitted number range is from 0 to 4294967295.
The syntax for unsigned number images is the same as for integer numbers. The usage of minus sign (UnaryMinus) is not allowed for an image of an unsigned number.
unsigned64
64 bit unsigned integer.
unsigned64
Values of this domain occupy 8 bytes.
The permitted number range is from 0 to 2^64-1 = 18,446,744,073,709,551,615.
The syntax for unsigned64 number images is the same as for integer64 numbers. The usage of minus sign (UnaryMinus) is not allowed for an image of an unsigned64 number.
The set of operations for unsigned64 is similar to the one for Unsigned.
unsignedNative
Unsigned integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
unsignedNative
real
Float-pointing number.
real
Values of this domain occupy 8 bytes. This numerical real domain is introduced for the user's convenience only. All arithmetic, comparison, and assignment operations are applied to values of real domain.
The permitted number range is -1.7e+308 to 1.7e+308. Values from integral domains are automatically converted to real numbers when necessary.
The syntax for the floating-point number literal is determined by the Real rule:
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
Float-pointing number.
real32
Values of this domain occupy 4 bytes. This numerical real32 domain is introduced for the user's convenience only. All arithmetic, comparison, and assignment operations can be applied to values of real32 domain.
The permitted number range is -3.4e+38 to 3.4e+38.
The syntax of real32 literals is the same as real lietrals.
pointer
A pointer to a memory address.
pointer
A pointer directly corresponds to memory addresses. Only the equality operation can be applied to the values of this domain. There is a built-in null constant for this type
pointerTo
pointerTo{Type} represents a pointer to a value of type Type. It's definition is like this (but it is built-in):
domains pointerTo{Type} = pointerTo(Type Value).
handle
A handle is used for Windows API function call. Values of this domain has the same size as a pointer (i.e. 4 on 32bit platfor and 8 on 64bit platform).
There are no operations for this domain and cannot be converted (except uncheckedConvert) to/from other domains.
There is a built-in nullHandle and invalidHandle constant for this type
boolean
Boolean values.
boolean
This domain is introduced for the user convenience only. It is treated as usual compound domain with the following definition:
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 the constants of this domain. The compiler automatically builds the corresponding compound terms from such constants whenever it's in need. At the runtime the 1st field of this structure contains the address of the corresponding domain descriptor and the 2nd field contains either zero (for class facts sections) or pointer to an object (i.e. This, for object facts sections).