Difference between revisions of "Language Reference/Built-in entities/Domains"

From wiki.visual-prolog.com
(string8 literals)
 
(9 intermediate revisions by 3 users not shown)
Line 2: Line 2:
|-
|-
|[[#any|any]]
|[[#any|any]]
|Universal term type.
|Universal term type
|-
|-
|[[#char|char]]
|[[#char|char]]
|Wide (two-bytes) character.
|Unicode character (16-bit)
|-
|-
|[[#string|string]]
|[[#string|string]]
|Wide zero-terminated sequence of wide characters.
|UTF-16 zero-terminated string
|-
|-
|[[#string8|string8]]
|[[#string8|string8]]
|Zero-terminated sequence of ASCII (one-byte) characters.
|Zero-terminated 8-bit string typically in UTF-8 encoding
|-
|-
|[[#symbol|symbol]]
|[[#symbol|symbol]]
|Wide zero-terminated sequence of wide characters.
|Interned UTF-16 string (global symbol table)
|-
|-
|[[#binary|binary]]
|[[#binary|binary]]
|Sequence of bytes.
|Byte sequence (non-scanned)
|-
|-
|[[#binaryNonAtomic|binaryNonAtomic]]
|[[#binaryNonAtomic|binaryNonAtomic]]
|Sequence of bytes.
|Byte sequence (GC-scanned; may contain pointers)
|-
|-
|[[#integer|integer]]
|[[#integer|integer]]
|32 bit signed integer.
|32-bit signed integer
|-
|-
|[[#integer64|integer64]]
|[[#integer64|integer64]]
|64 bit signed integer.
|64-bit signed integer
|-
|-
|[[#integerNative|integerNative]]
|[[#integerNative|integerNative]]
|Signed integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
|Platform-sized signed integer (32/64-bit)
|-
|-
|[[#unsigned|unsigned]]
|[[#unsigned|unsigned]]
|32 bit unsigned integer.
|32-bit unsigned integer
|-
|-
|[[#unsigned64|unsigned64]]
|[[#unsigned64|unsigned64]]
|64 bit unsigned integer.
|64-bit unsigned integer
|-
|-
|[[#unsignedNative|unsignedNative]]
|[[#unsignedNative|unsignedNative]]
|Unsigned integer with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
|Platform-sized unsigned integer (32/64-bit)
|-
|-
|[[#real|real]]
|[[#real|real]]
|Float-pointing number.
|Floating-point number (64-bit)
|-
|-
|[[#real32|real32]]
|[[#real32|real32]]
|Float-pointing number.
|Floating-point number (32-bit)
|-
|-
|[[#pointer|pointer]]
|[[#pointer|pointer]]
|pointer to a memory address.
|Pointer value
|-
|[[#pointerTo|pointerTo]]
|Pointer to a value of a given type
|-
|-
|[[#handle|handle]]
|[[#handle|handle]]
|a handle (e.g. native file and windows handles).
|Operating system handle (e.g., Windows)
|-
|-
|[[#boolean|boolean]]
|[[#boolean|boolean]]
|Boolean values.
|Boolean values
|-
|-
|[[#factDB|factDB]]
|[[#factDB|factDB]]
|Descriptors of named internal databases.
|Descriptor of a named internal database
|-
|-
|[[#compareResult|compareResult]]
|[[#compareResult|compareResult]]
|Values of comparison result.
|Result of a comparison
|}
|}


Line 68: Line 71:
<vip>any</vip>
<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.
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 ====
==== char ====


Wide character.
Unicode character.


<vip>char</vip>
<vip>char</vip>


The values of this domain are UNICODE characters. Implemented as 2 unsigned bytes.
Values of this domain are Unicode characters implemented as two 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:
Only assignment and comparison (lexicographical) are defined. The image of a character has the following syntax:


<vipbnf><Char_image> :
<vipbnf><Char_image> :
Line 86: Line 89:
       <Digit>
       <Digit>
       <Graphical_symbol>
       <Graphical_symbol>
       \ <Escape_seq>
       <Escape_seq>
<Escape_seq>:
<Escape_seq>:
       t
       \t
       n
       \n
       r
       \r
       \
       \\
       '
       \'
       "
       \"
       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> corresponds to four hexadecimal digits. The backslash and single quote can only be represented by escape sequences.


==== compareResult ====
==== compareResult ====


A built-in domain that represents 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.
The result domain for comparisons (e.g., {{lang2|Built-in entities|compare|compare/2->}}).
 
<vip>domains
<vip>domains
   compareResult = less; equal; greater.
   compareResult = less; equal; greater.
Line 107: Line 111:
==== string ====
==== string ====


Wide zero terminated sequence of wide characters.
UTF-16 strings.


<vip>string</vip>
<vip>string</vip>


A string is a sequence of UNICODE characters. It's implemented as a pointer to the wide zero-terminated array of wide characters. Only assignment and comparison (in the lexicographical sense) operations are applied to values of this domain.
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 can be specified as a set of sequences of characters surrounded by the double quotes.
In source code a string literal is one or more parts surrounded by double quotes:


<vipbnf><StringLiteral>:
<vipbnf><StringLiteral>:
Line 122: Line 126:
   " CharacterValue-list-opt "</vipbnf>
   " CharacterValue-list-opt "</vipbnf>


A string literal consists of one or more <vpbnf><StringLiteralPart></vpbnf>'s, which are concatenated. <vpbnf><StringLiteralPart></vpbnf>'s starting with <vp>@</vp> does not use escape sequences, whereas <vpbnf><StringLiteralPart></vpbnf>'s without <vp>@</vp> uses the following escape sequences:
Parts starting with <vp>@</vp> do not use escape sequences; parts without <vp>@</vp> use the following escapes:


*<vp>\\</vp> representing <vp>\</vp>
* <vp>\\</vp> representing <vp>\</vp>
*<vp>\t</vp> representing Tab-character
* <vp>\t</vp> representing a tab character
*<vp>\n</vp> representing newline-character
* <vp>\n</vp> representing a newline character
*<vp>\r</vp> representing carriage return
* <vp>\r</vp> representing a carriage return
*<vp>\'</vp> representing single quote
* <vp>\'</vp> representing a single quote
*<vp>\"</vp> representing double quote
* <vp>\"</vp> representing a double quote
*<vp>\u</vp> followed by exactly four <vpbnf><HexadecimalDigit></vpbnf>'s representing the Unicode character corresponding to the digits.
* <vp>\u</vp> followed by exactly four <vpbnf><HexadecimalDigit></vpbnf> values representing the Unicode character


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).
Double quotes in strings must be written using the escape sequence (single quotes may be written directly or escaped).


==== string8 ====
==== string8 ====


A built-in domain inhabited by 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.
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 <vp>string</vp> literal and as a <vp>string8</vp> literal, depending on context:
* When a <vp>string8</vp> value is expected, the literal is compiled as UTF-8 bytes with a trailing zero
* When a <vp>string</vp> 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 <vp>string8</vp>) or by explicit conversion.
 
{{Example|
<vip>
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)
</vip>
}}


==== symbol ====
==== symbol ====


Wide zero terminated sequence of wide characters.
UTF-16 strings with the same representation as <vp>string</vp>, but also stored in a global symbol table.


<vip>symbol</vip>
<vip>symbol</vip>


Similar to a string, a symbol is also a sequence of the UNICODE characters. It's implemented as a pointer to an entry in a symbol table that contains strings. The operations that can be applied to symbols are the same as for strings.
A <vp>symbol</vp> 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.


The image of a symbol is represented with a ''<string_literal>'' (any string surrounded by the double quotes).
<vp>symbol</vp> is a subtype of <vp>string</vp>, so a symbol can be used wherever a string is expected. The opposite is not automatic; to obtain a symbol from a string, explicitly <vp>convert</vp> to the symbol domain (or a subtype).


Symbols and strings are largely interchangeable but they are stored differently. Symbols are kept in a look-up table and their addresses, rather than the symbols themselves, are stored to represent objects. This means that symbols can be matched very quickly and, if a symbol occurs repeatedly in a program, it can be stored very compactly. Strings are not kept in a look-up table. Visual Prolog examines strings character-by-character whenever they are to be matched.
Equality is efficient for <vp>symbol</vp> values (pointer equality). Other comparisons behave like the corresponding <vp>string</vp> operations.


==== binary ====
==== binary ====


Sequence of N bytes.
Sequence of bytes.


<vip>binary</vip>
<vip>binary</vip>


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.
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 situated in the '''4 bytes''' immediately preceding this sequence of bytes. The 4 bytes contains:
The length of a binary term is stored in the four bytes immediately preceding the sequence:


<vip>TotalNumberOfBytesOccupiedByBinary = ByteLen + 4 </vip>
<vip>TotalNumberOfBytesOccupiedByBinary = ByteLen + 4</vip>


where <vp>ByteLen</vp> - is the length of the binary term and 4 is number of bytes occupied by size field.
where <vp>ByteLen</vp> is the length of the sequence and <vp>4</vp> is the size field.


Only assignment and comparison operations are applied to values of '''binary domain'''.
Only assignment and comparison are defined.


Two binary terms are compared in the following way:
Two binaries are compared as follows:


*If they are of different sizes, the bigger is considered larger.
* If sizes differ, the larger size is greater
*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.
* 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 the <vpbnf><Binary></vpbnf> rules:
The text syntax for binary images is determined by <vpbnf><Binary></vpbnf>:


<vipbnf><Binary> :
<vipbnf><Binary> :
Line 178: Line 201:
       <Expression></vipbnf>
       <Expression></vipbnf>


Each ''expression'' should be calculate on compiling time and its value should be in the range from <vp>0</vp> to <vp>255</vp>.
Each expression must be computable at compile time and have a value in the range <vp>0</vp>..&nbsp;<vp>255</vp>.


==== binaryNonAtomic ====
==== binaryNonAtomic ====


Sequence of N bytes.
Sequence of bytes.


<vip>binaryNonAtomic</vip>
<vip>binaryNonAtomic</vip>


Same as [[#binary|binary]], but can contain pointers because it is scanned by the garbage collector.
Same as [[#binary|binary]], but may contain pointers and is scanned by the garbage collector.


==== integer ====
==== integer ====


32 bit signed 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, {{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.
Values occupy 4 bytes. Arithmetic (<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->}} are defined.


The permitted number range is from <vp>-2147483648</vp> to <vp>2147483647</vp>.
Range: <vp>-2147483648</vp> .. <vp>2147483647</vp>.


The syntax for the <vp>integer</vp> literal is determined by the <vpbnf><Integer></vpbnf> rule:
Literals follow <vpbnf><Integer></vpbnf>:


<vipbnf><Integer> :
<vipbnf><Integer> :
Line 222: Line 245:
==== integer64 ====
==== integer64 ====


64 bit signed integer.
64-bit signed integer.


<vip>integer64</vip>
<vip>integer64</vip>


Values of this domain occupy 8 bytes.
Values occupy 8 bytes.


The permitted number range is from <vp>-2^63 = -9223372036854775808</vp> to <vp>2^63-1 = 9223372036854775807</vp>.
Range: <vp>-2^63 = -9223372036854775808</vp> .. <vp>2^63-1 = 9223372036854775807</vp>.


The syntax for <vp>integer64</vp> literal is the same as <vpbnf><Integer></vpbnf> rule.
Literals use the same syntax as <vpbnf><Integer></vpbnf>. The available operations mirror those for <vpbnf><Integer></vpbnf>.
 
The set of operations for <vp>integer64</vp> is similar to the one for <vpbnf><Integer></vpbnf>.


==== integerNative ====
==== integerNative ====


Signed integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
Platform-sized signed integer (32-bit in 32-bit programs; 64-bit in 64-bit programs).


<vip>integerNative</vip>
<vip>integerNative</vip>
Line 242: Line 263:
==== unsigned ====
==== unsigned ====


32 bit unsigned integer.
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|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.
Values occupy 4 bytes. Arithmetic (<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->}} are defined.


The permitted number range is from <vp>0</vp> to <vp>4294967295</vp>.
Range: <vp>0</vp> .. <vp>4294967295</vp>.


The syntax for <vp>unsigned</vp> number images is the same as for <vp>integer</vp> numbers. The usage of minus sign (<vpbnf><UnaryMinus></vpbnf>) is not allowed for an image of an <vp>unsigned</vp> number.
Literals use the same syntax as <vp>integer</vp> numbers. A leading minus (<vpbnf><UnaryMinus></vpbnf>) is not allowed for an <vp>unsigned</vp> literal.


==== unsigned64 ====
==== unsigned64 ====


64 bit unsigned integer.
64-bit unsigned integer.


<vip>unsigned64</vip>
<vip>unsigned64</vip>


Values of this domain occupy 8 bytes.
Values occupy 8 bytes.


The permitted number range is from <vp>0</vp> to <vp>2^64-1 = 18,446,744,073,709,551,615</vp>.
Range: <vp>0</vp> .. <vp>2^64-1 = 18,446,744,073,709,551,615</vp>.


The syntax for <vp>unsigned64</vp> number images is the same as for <vp>integer64</vp> numbers. The usage of minus sign (<vpbnf><UnaryMinus></vpbnf>) is not allowed for an image of an <vp>unsigned64</vp> number.
Literals use the same syntax as <vp>integer64</vp> numbers. A leading minus (<vpbnf><UnaryMinus></vpbnf>) is not allowed for an <vp>unsigned64</vp> literal.


The set of operations for <vp>unsigned64</vp> is similar to the one for <vpbnf><Unsigned></vpbnf>.
Operations mirror those for <vpbnf><Unsigned></vpbnf>.


==== unsignedNative ====
==== unsignedNative ====


Unsigned integer number with platform size (32 bit in a 32 bit program; 64 bit in a 64 bit program).
Platform-sized unsigned integer (32-bit in 32-bit programs; 64-bit in 64-bit programs).


<vip>unsignedNative</vip>
<vip>unsignedNative</vip>
Line 274: Line 295:
==== real ====
==== real ====


Float-pointing number.
Floating-point number.


<vip>real</vip>
<vip>real</vip>


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 <vp>real</vp> domain.
Values occupy 8 bytes. All arithmetic, comparison, and assignment operations are defined.


The permitted number range is <vp>-1.7e+308</vp> to <vp>1.7e+308</vp>. Values from integral domains are automatically converted to real numbers when necessary.
Range: approximately <vp>-1.7e+308</vp> .. <vp>1.7e+308</vp>. Integral values are implicitly converted to <vp>real</vp> when needed.


The syntax for the floating-point number literal is determined by the <vpbnf><Real></vpbnf> rule:
Floating-point literals follow <vpbnf><Real></vpbnf>:


<vipbnf><Real> :
<vipbnf><Real> :
Line 305: Line 326:
==== real32 ====
==== real32 ====


Float-pointing number.
Floating-point number.


<vip>real32</vip>
<vip>real32</vip>


Values of this domain occupy 4 bytes. This numerical <vp>real32</vp> domain is introduced for the user's convenience only. All arithmetic, comparison, and assignment operations can be applied to values of <vp>real32</vp> domain.
Values occupy 4 bytes. All arithmetic, comparison, and assignment operations are defined.


The permitted number range is <vp>-3.4e+38</vp> to <vp>3.4e+38</vp>.
Range: approximately <vp>-3.4e+38</vp> .. <vp>3.4e+38</vp>.


The syntax of real32 literals is the same as <vp>real</vp> lietrals.
The syntax of <vp>real32</vp> literals is the same as for <vp>real</vp> literals.


==== pointer ====
==== pointer ====
Line 321: Line 342:
<vip>pointer</vip>
<vip>pointer</vip>


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
Corresponds directly to memory addresses. Only equality comparison is defined. 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>. Conceptually (it is built-in), it can be viewed as:
 
<vip>domains
    pointerTo{Type} = pointerTo(Type Value).</vip>


==== handle ====
==== 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).
Used for Windows API calls. Values have the same size as a pointer (4 bytes on 32-bit, 8 bytes on 64-bit platforms).


There are no operations for this domain and cannot be converted (except uncheckedConvert) to/from other domains.
No operations are defined for this domain, and values cannot be converted to/from other domains (except via <vp>uncheckedConvert</vp>).


There is a built-in [[#nullHandle|nullHandle]] and [[#invalidHandle|invalidHandle]] constant  for this type
There are built-in constants: [[#nullHandle|nullHandle]] and [[#invalidHandle|invalidHandle]].


==== boolean ====
==== boolean ====
Line 337: Line 365:
<vip>boolean</vip>
<vip>boolean</vip>


This domain is introduced for the user convenience only. It is treated as usual compound domain with the following definition:
This domain is provided for convenience and is treated as a normal compound domain:


<vip>domains
<vip>domains
   boolean = false(); true().</vip>
   boolean = false; true.</vip>


==== factDB ====
==== factDB ====
Line 353: Line 381:
   factDB = struct @factdb( named_internal_database_domain, object ).</vip>
   factDB = struct @factdb( named_internal_database_domain, object ).</vip>


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 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., <vp>This</vp> for object facts sections).
<noinclude>{{LanguageReferenceSubarticle|Built-in entities/Domains}}</noinclude>
<noinclude>{{LanguageReferenceSubarticle|Built-in entities/Domains}}</noinclude>

Latest revision as of 11:13, 21 August 2025

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.

Example
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).