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

From wiki.visual-prolog.com
m (Categorized)
m (Remove arity from section names (to improve links from IDE))
Line 3: Line 3:
{|{{prettytable}}
{|{{prettytable}}
|-
|-
|[[#assert/1|assert/1]]
|[[#assert|assert/1]]
|Insert the specified fact at the end of the matched internal facts database.
|Insert the specified fact at the end of the matched internal facts database.
|-
|-
|[[#asserta/1|asserta/1]]
|[[#asserta|asserta/1]]
|Insert a fact at the beginning of the matched internal facts database.
|Insert a fact at the beginning of the matched internal facts database.
|-
|-
|[[#assertz/1|assertz/1]]
|[[#assertz|assertz/1]]
|Insert a fact at the end of the matched internal facts database.
|Insert a fact at the end of the matched internal facts database.
|-
|-
|[[#bound/1|bound/1]] <vp>determ</vp>
|[[#bound|bound/1]] <vp>determ</vp>
|Test whether the specified variable is bound to a value.
|Test whether the specified variable is bound to a value.
|-
|-
|[[#class_Name/0->|class_Name/0->]]
|[[#class_Name|class_Name/0->]]
|This compile time predicate returns the string ''ClassName'' that represents the name of the current interface or class.
|This compile time predicate returns the string ''ClassName'' that represents the name of the current interface or class.
|-
|-
|[[#compare/2->|compare/2->]]
|[[#compare|compare/2->]]
|Returns the result of the variables' comparison.
|Returns the result of the variables' comparison.
|-
|-
|[[#convert/2->|convert/2->]]
|[[#convert|convert/2->]]
|Checked term conversion.
|Checked term conversion.
|-
|-
|[[#digitsOf/1->|digitsOf/1->]]
|[[#digitsOf|digitsOf/1->]]
|Returns precision of the specified floating-point domain.
|Returns precision of the specified floating-point domain.
|-
|-
|[[#errorExit/1|errorExit/1]] <vp>erroneous</vp>
|[[#errorExit|errorExit/1]] <vp>erroneous</vp>
|Performs a run-time error with the specified return code ''ErrorNumber'' and sets the internal error information.
|Performs a run-time error with the specified return code ''ErrorNumber'' and sets the internal error information.
|-
|-
|[[#fail/0|fail/0]] <vp>failure</vp>
|[[#fail|fail/0]] <vp>failure</vp>
|Invoke backtracking.
|Invoke backtracking.
|-
|-
|[[#free/1|free/1]] <vp>determ</vp>
|[[#free|free/1]] <vp>determ</vp>
|Check whether a variable is free.
|Check whether a variable is free.
|-
|-
|[[#hasDomain/2|hasDomain/2]]
|[[#hasDomain|hasDomain/2]]
|Checks whether the variable ''VariableName'' has the domain ''domainName''.
|Checks whether the variable ''VariableName'' has the domain ''domainName''.
|-
|-
|[[#isErroneous/1|isErroneous/1]] <vp>determ</vp>
|[[#isErroneous|isErroneous/1]] <vp>determ</vp>
|Returns the lower bound value of the specified numeric domain.
|Returns the lower bound value of the specified numeric domain.
|-
|-
|[[#lowerBound/1->|lowerBound/1->]]
|[[#lowerBound|lowerBound/1->]]
|Returns the lower bound value of the specified numeric domain.
|Returns the lower bound value of the specified numeric domain.
|-
|-
|[[#maxDigits/1->|maxDigits/1->]]
|[[#maxDigits|maxDigits/1->]]
|Retrieves the value of digits (precision) of the basic domain corresponding to the specified floating-point domain ''domainName''.
|Retrieves the value of digits (precision) of the basic domain corresponding to the specified floating-point domain ''domainName''.
|-
|-
|[[#not/1|not/1]] <vp>determ</vp>
|[[#not|not/1]] <vp>determ</vp>
|Negate the result (success/fail) of subgoal.
|Negate the result (success/fail) of subgoal.
|-
|-
|[[#predicate_fullname/0->|predicate_fullname/1->]]
|[[#predicate_fullname|predicate_fullname/1->]]
|This compile time predicate returns the string ''PredicateFullName'' that represent the name of the predicate in which clause body '''predicate_name''' is called. The returned predicate name is qualified with a scope's name.
|This compile time predicate returns the string ''PredicateFullName'' that represent the name of the predicate in which clause body '''predicate_name''' is called. The returned predicate name is qualified with a scope's name.
|-
|-
|[[#predicate_name/0->|predicate_name/0->]]
|[[#predicate_name|predicate_name/0->]]
|This compile time predicate returns the string ''PredicateName'' that represents the name of the predicate in which clause body '''predicate_name''' is called.
|This compile time predicate returns the string ''PredicateName'' that represents the name of the predicate in which clause body '''predicate_name''' is called.
|-
|-
|[[#retract/1|retract/1]] <vp>nondeterm</vp>
|[[#retract|retract/1]] <vp>nondeterm</vp>
|Remove a matched fact from the matched internal facts database.
|Remove a matched fact from the matched internal facts database.
|-
|-
|[[#retractall/1|retractall/1]]
|[[#retractall|retractall/1]]
|Remove all matching facts from the matched internal facts database.
|Remove all matching facts from the matched internal facts database.
|-
|-
|[[#retractFactDb/1|retractFactDb/1]]
|[[#retractFactDb|retractFactDb/1]]
|Remove all facts from the specified named internal facts database.
|Remove all facts from the specified named internal facts database.
|-
|-
|[[#sizeBitsOf/1->|sizeBitsOf/1->]]
|[[#sizeBitsOf|sizeBitsOf/1->]]
|Retrieves the number of bits occupied in memory by an entity of the specified domain ''DomainName''.
|Retrieves the number of bits occupied in memory by an entity of the specified domain ''DomainName''.
|-
|-
|[[#sizeOf/1->|sizeOf/1->]]
|[[#sizeOf|sizeOf/1->]]
|Retrieves the number of bytes occupied in memory by the specified term.
|Retrieves the number of bytes occupied in memory by the specified term.
|-
|-
|[[#sizeOfDomain/1->|sizeOfDomain/1->]]
|[[#sizeOfDomain|sizeOfDomain/1->]]
|Retrieves the number of bytes occupied in memory by the entity of the specified domain ''DomainName''.
|Retrieves the number of bytes occupied in memory by the entity of the specified domain ''DomainName''.
|-
|-
|[[#sourcefile_lineno/0->|sourcefile_lineno/0->]]
|[[#sourcefile_lineno|sourcefile_lineno/0->]]
|Returns the current line number in the source file processed by the compiler .
|Returns the current line number in the source file processed by the compiler .
|-
|-
|[[#sourcefile_name/0->|sourcefile_name/0->]]
|[[#sourcefile_name|sourcefile_name/0->]]
|Returns the name of the source file processed by the compiler.
|Returns the name of the source file processed by the compiler.
|-
|-
|[[#sourcefile_timestamp/0->|sourcefile_timestamp/0->]]
|[[#sourcefile_timestamp|sourcefile_timestamp/0->]]
|Returns the string representing the date and time of the source file processed by the compiler.
|Returns the string representing the date and time of the source file processed by the compiler.
|-
|-
|[[#succeed/0|succeed/0]]
|[[#succeed|succeed/0]]
|The predicate '''succeed/0''' will always succeed.
|The predicate '''succeed/0''' will always succeed.
|-
|-
|[[#toBinary/1->|toBinary/1->]]
|[[#toBinary|toBinary/1->]]
|Converts the specified Term to the binary representation.
|Converts the specified Term to the binary representation.
|-
|-
|[[#toBoolean/1->|toBoolean/1->]]
|[[#toBoolean|toBoolean/1->]]
|The purpose of this meta-predicate is to convert the deterministic call (to a predicate or fact) to the procedure that returns the value of '''boolean''' domain.
|The purpose of this meta-predicate is to convert the deterministic call (to a predicate or fact) to the procedure that returns the value of '''boolean''' domain.
|-
|-
|[[#toString/1->|toString/1->]]
|[[#toString|toString/1->]]
|Converts the specified ''Term'' to the string representation.
|Converts the specified ''Term'' to the string representation.
|-
|-
|[[#toTerm/1->|toTerm/1->]]
|[[#toTerm|toTerm/1->]]
|Converts the string/binary representation of the specified term ''SrcTerm'' into representation corresponding to the domain of ''PrologTerm'' variable of the return value.
|Converts the string/binary representation of the specified term ''SrcTerm'' into representation corresponding to the domain of ''PrologTerm'' variable of the return value.
|-
|-
|[[#tryToTerm/1->|tryToTerm/1->]]
|[[#tryToTerm|tryToTerm/1->]]
|Converts the string/binary representation of the specified term ''SrcTerm'' into representation corresponding to the domain of ''PrologTerm'' variable of the return value.
|Converts the string/binary representation of the specified term ''SrcTerm'' into representation corresponding to the domain of ''PrologTerm'' variable of the return value.
|-
|-
|[[#tryConvert/2->|tryConvert/2->]] <vp>determ</vp>
|[[#tryConvert|tryConvert/2->]] <vp>determ</vp>
|Checks whether the input term ''InputTerm'' can be strictly converted into the specified domain ''returnDomain'' and returns the converted term ''ReturnTerm''.
|Checks whether the input term ''InputTerm'' can be strictly converted into the specified domain ''returnDomain'' and returns the converted term ''ReturnTerm''.
|-
|-
|[[#uncheckedConvert/2->|uncheckedConvert/2->]]
|[[#uncheckedConvert|uncheckedConvert/2->]]
|Unchecked conversion of domains.
|Unchecked conversion of domains.
|-
|-
|[[#upperBound/1->|upperBound/1->]]
|[[#upperBound|upperBound/1->]]
|Returns the upper bound value of the specified numeric domain.
|Returns the upper bound value of the specified numeric domain.
|}
|}
Line 125: Line 125:
|}
|}


==== assert/1 ====
==== assert ====


<vip>assert : (<fact-term> FactTerm).</vip>
<vip>assert : (<fact-term> FactTerm).</vip>
Line 131: Line 131:
Insert the specified fact at the end of the matched internal facts database
Insert the specified fact at the end of the matched internal facts database


<vp>assert(Fact)</vp> inserts <vp>Fact</vp> in the matched internal facts database after any other stored facts for the corresponding database predicate. <vp>Fact</vp> must be a term belonging to the domain of an internal facts database. <vp>assert/1</vp> applied to a single fact changes the existing instance of a fact to the specified one. <vp>assert/1</vp> has the same effect as [[#assertz/1|assertz/1]]. See also [[#asserta/1|asserta/1]]
<vp>assert(Fact)</vp> inserts <vp>Fact</vp> in the matched internal facts database after any other stored facts for the corresponding database predicate. <vp>Fact</vp> must be a term belonging to the domain of an internal facts database. <vp>assert/1</vp> applied to a single fact changes the existing instance of a fact to the specified one. <vp>assert/1</vp> has the same effect as [[#assertz|assertz/1]]. See also [[#asserta|asserta/1]]


Notice that the combination of [[#retract/1|retract/1]] and <vp>assert/1</vp> like the following can lead to endless loop:
Notice that the combination of [[#retract|retract/1]] and <vp>assert/1</vp> like the following can lead to endless loop:


<vip>loop() :-
<vip>loop() :-
Line 147: Line 147:
Assert to a fact declared as determ, but the fact instance already exists.
Assert to a fact declared as determ, but the fact instance already exists.


==== asserta/1 ====
==== asserta ====


<vip>asserta : (<fact-term> FactTerm).</vip>
<vip>asserta : (<fact-term> FactTerm).</vip>
Line 155: Line 155:
'''Description'''
'''Description'''


The <vp>asserta(Fact)</vp> predicate inserts a <vp>Fact</vp> in the matched internal facts database before any other stored facts for the corresponding predicate. The <vp>Fact</vp> must be a term belonging to the domain of an internal facts database. The <vp>asserta/1</vp> applied to a single fact changes the existing instance of a fact to the specified one. See also [[#assert/1|assert/1]] and [[#assertz/1|assertz/1]].
The <vp>asserta(Fact)</vp> predicate inserts a <vp>Fact</vp> in the matched internal facts database before any other stored facts for the corresponding predicate. The <vp>Fact</vp> must be a term belonging to the domain of an internal facts database. The <vp>asserta/1</vp> applied to a single fact changes the existing instance of a fact to the specified one. See also [[#assert|assert/1]] and [[#assertz|assertz/1]].


'''Exceptions'''
'''Exceptions'''
Line 161: Line 161:
Assert to a fact declared as determ, but the fact instance already exists.
Assert to a fact declared as determ, but the fact instance already exists.


==== assertz/1 ====
==== assertz ====


<vip>assertz : (<fact-term> FactTerm).</vip>
<vip>assertz : (<fact-term> FactTerm).</vip>


<vp>assertz</vp> does exactly the same as the [[#assert/1|assert/1]] predicate.
<vp>assertz</vp> does exactly the same as the [[#assert|assert/1]] predicate.


==== bound/1 ====
==== bound ====


<vip>bound : (<variable> Variable) determ.</vip>
<vip>bound : (<variable> Variable) determ.</vip>
Line 177: Line 177:
The <vp>bound(Variable)</vp> succeeds if <vp>Variable</vp> is bound and fails if it is free. The <vp>bound</vp> predicate is used to control flow patterns and to check the binding of reference variables. The <vp>bound</vp> predicate treats the specified <vp>Variable</vp> as bound if any of it's part is instantiated.
The <vp>bound(Variable)</vp> succeeds if <vp>Variable</vp> is bound and fails if it is free. The <vp>bound</vp> predicate is used to control flow patterns and to check the binding of reference variables. The <vp>bound</vp> predicate treats the specified <vp>Variable</vp> as bound if any of it's part is instantiated.


See also [[#free/1|free/1]].
See also [[#free|free/1]].


==== class_Name/0-> ====
==== class_Name ====


<vip>class_Name : () -> string ClassName.</vip>
<vip>class_Name : () -> string ClassName.</vip>
Line 185: Line 185:
This compile time predicate returns the string <vp>ClassName</vp> that represents the name of the current interface or class.
This compile time predicate returns the string <vp>ClassName</vp> that represents the name of the current interface or class.


==== compare/2-> ====
==== compare ====


<vip>compare : (A Left, A Right) -> compareResult CompareResult.</vip>
<vip>compare : (A Left, A Right) -> compareResult CompareResult.</vip>
Line 199: Line 199:
<vp>CompareResult</vp> = compare("<vp>123</vp>","<vp>abc</vp>")
<vp>CompareResult</vp> = compare("<vp>123</vp>","<vp>abc</vp>")


==== convert/2-> ====
==== convert ====


<vip>convert : (<type> Type, Term) -> <type> Converted.</vip>
<vip>convert : (<type> Type, Term) -> <type> Converted.</vip>
Line 221: Line 221:
'''Remarks'''
'''Remarks'''


The <vp>convert</vp> predicate performs a clean and genuine conversion of the given <vp>InputTerm</vp>, returning a new term <vp>ReturnTerm</vp> of the specified new domain ''returnDomain''. If <vp>convert</vp> cannot perform the required conversion, it rises errors. The similar functionality is provided by the [[#tryConvert/2->|tryConvert/2->]] predicate, but <vp>tryConvert-></vp> fails and does not produce any runtime errors if it cannot perform the conversion.
The <vp>convert</vp> predicate performs a clean and genuine conversion of the given <vp>InputTerm</vp>, returning a new term <vp>ReturnTerm</vp> of the specified new domain ''returnDomain''. If <vp>convert</vp> cannot perform the required conversion, it rises errors. The similar functionality is provided by the [[#tryConvert|tryConvert/2->]] predicate, but <vp>tryConvert-></vp> fails and does not produce any runtime errors if it cannot perform the conversion.


'''Allowed conversions:'''
'''Allowed conversions:'''
Line 232: Line 232:
*Between [http://wiki.visual-prolog.com/index.php?title=How_To_Remove_Reference_Domains_from_a_Project reference] domains and corresponding non-reference domains.
*Between [http://wiki.visual-prolog.com/index.php?title=How_To_Remove_Reference_Domains_from_a_Project reference] domains and corresponding non-reference domains.


The contrast to these is [[#uncheckedConvert/2->|uncheckedConvert/2->]] predicate, which performs an unchecked conversion between terms from any domains, which have the same bit-size.
The contrast to these is [[#uncheckedConvert|uncheckedConvert/2->]] predicate, which performs an unchecked conversion between terms from any domains, which have the same bit-size.


The <vp>convert/2-></vp> (or [[#tryConvert/2->|tryConvert/2->]]) predicate accomplishes a checked explicit conversion, when the source and target domains are statically known during the compilation. The result of an explicit conversion can be one of the following:
The <vp>convert/2-></vp> (or [[#tryConvert|tryConvert/2->]]) predicate accomplishes a checked explicit conversion, when the source and target domains are statically known during the compilation. The result of an explicit conversion can be one of the following:


*'''ok''' the successful conversion to the target domain;
*'''ok''' the successful conversion to the target domain;
Line 254: Line 254:


*The range is considered first during such conversion. If the ranges of source and target do not intersect, then an error is produced. If the ranges of source and target only partially intersect, then run-time checking is generated. Also, if one of domains is real and another is an integral one, then the integer range is converted to the real range before the comparison.
*The range is considered first during such conversion. If the ranges of source and target do not intersect, then an error is produced. If the ranges of source and target only partially intersect, then run-time checking is generated. Also, if one of domains is real and another is an integral one, then the integer range is converted to the real range before the comparison.
*When input term in real and output is integer, then <vp>convert/2-></vp> and [[#tryConvert/2->|tryConvert/2->]] predicates truncate the input value to the nearest integer value, which is nearer to zero.
*When input term in real and output is integer, then <vp>convert/2-></vp> and [[#tryConvert|tryConvert/2->]] predicates truncate the input value to the nearest integer value, which is nearer to zero.


'''Conversions of Interface Types'''
'''Conversions of Interface Types'''
Line 271: Line 271:
*Unsupported interface type.
*Unsupported interface type.


==== digitsOf/1-> ====
==== digitsOf ====


<vip>digitsOf : (<real-domain> Domain) -> unsigned.</vip>
<vip>digitsOf : (<real-domain> Domain) -> unsigned.</vip>
Line 287: Line 287:
The compiler guarantees that values of the domain ''domainName'' will have at least <vpbnf><Precision></vpbnf> number of significant decimal digits.
The compiler guarantees that values of the domain ''domainName'' will have at least <vpbnf><Precision></vpbnf> number of significant decimal digits.


==== errorExit/1 ====
==== errorExit ====


<vip>errorExit : (unsigned ErrorNumber) erroneous.</vip>
<vip>errorExit : (unsigned ErrorNumber) erroneous.</vip>
Line 293: Line 293:
Performs a run-time error with the specified return code <vp>ErrorNumber</vp>, which can be used in the [[#Try-catch-finally|try-catch-finally]].
Performs a run-time error with the specified return code <vp>ErrorNumber</vp>, which can be used in the [[#Try-catch-finally|try-catch-finally]].


==== fail/0 ====
==== fail ====


<vip>fail : () failure.</vip>
<vip>fail : () failure.</vip>
Line 303: Line 303:
The <vp>fail</vp> predicate forces failure of a predicate and, hence, always causes backtracking. In a clause ended with <vp>fail</vp>, it cannot bind output arguments for a clause.
The <vp>fail</vp> predicate forces failure of a predicate and, hence, always causes backtracking. In a clause ended with <vp>fail</vp>, it cannot bind output arguments for a clause.


==== free/1 ====
==== free ====


<vip>free : (<variableName> Variable) determ.</vip>
<vip>free : (<variableName> Variable) determ.</vip>
Line 317: Line 317:
The <vp>free</vp> predicate succeeds if the specified <vp>Variable</vp> is free and fails if <vp>Variable</vp> is bound. The <vp>free</vp> predicate treats the specified <vp>Variable</vp> as bound if any of it's part are instantiated.
The <vp>free</vp> predicate succeeds if the specified <vp>Variable</vp> is free and fails if <vp>Variable</vp> is bound. The <vp>free</vp> predicate treats the specified <vp>Variable</vp> as bound if any of it's part are instantiated.


See also [[#bound/1|bound/1]].
See also [[#bound|bound/1]].


==== hasDomain/2 ====
==== hasDomain ====


<vip>hasDomain : (<type> Type, <variable> Variable) procedure.</vip>
<vip>hasDomain : (<type> Type, <variable> Variable) procedure.</vip>
Line 333: Line 333:
The predicate declares that <vp>VariableName</vp> that belongs to the domain that is defined by the parameter ''domainName''. The ''domainName'' parameter should be the name of a standard or a user defined domain; this domain name should be explicitly specified at compile-time (that is, ''domainName'' cannot come from a variable).
The predicate declares that <vp>VariableName</vp> that belongs to the domain that is defined by the parameter ''domainName''. The ''domainName'' parameter should be the name of a standard or a user defined domain; this domain name should be explicitly specified at compile-time (that is, ''domainName'' cannot come from a variable).


==== lowerBound/1-> ====
==== lowerBound ====


<vip>lowerBound : (<numeric-domain> NumericDomain) -> <numeric-domain> LowerBound.</vip>
<vip>lowerBound : (<numeric-domain> NumericDomain) -> <numeric-domain> LowerBound.</vip>
Line 345: Line 345:
<vip>LowerBoundValue = lowerBound(domainName)</vip>
<vip>LowerBoundValue = lowerBound(domainName)</vip>


The <vp>lowerBound</vp> is a compiling-time predicate. The <vp>lowerBound</vp> returns the lower bound value <vp>LowerBoundValue</vp> of the specified numeric domain ''domainName''. The return value <vp>LowerBoundValue</vp> belongs to the same domain ''domainName''. The ''domainName'' parameter should be the name of any numerical domain; this domain name should be explicitly specified at compile-time (that is, ''domainName'' cannot come from a variable). See also [[#upperBound/1->|upperBound/1->]].
The <vp>lowerBound</vp> is a compiling-time predicate. The <vp>lowerBound</vp> returns the lower bound value <vp>LowerBoundValue</vp> of the specified numeric domain ''domainName''. The return value <vp>LowerBoundValue</vp> belongs to the same domain ''domainName''. The ''domainName'' parameter should be the name of any numerical domain; this domain name should be explicitly specified at compile-time (that is, ''domainName'' cannot come from a variable). See also [[#upperBound|upperBound/1->]].


'''Exceptions'''
'''Exceptions'''
Line 351: Line 351:
compile time error if the specified domain ''domainName'' is not numeric domain.
compile time error if the specified domain ''domainName'' is not numeric domain.


==== isErroneous/1 ====
==== isErroneous ====


<vip>isErroneous : (<fact-variable> FactVariable) determ.</vip>
<vip>isErroneous : (<fact-variable> FactVariable) determ.</vip>
Line 365: Line 365:
The predicate succeeds if the specified fact variable <vp>factVariableName</vp> has the <vp>erroneous</vp> value, otherwise it fails.
The predicate succeeds if the specified fact variable <vp>factVariableName</vp> has the <vp>erroneous</vp> value, otherwise it fails.


==== maxDigits/1-> ====
==== maxDigits ====


<vip>maxDigits : (<real-domain> RealDomain) -> unsigned MaxDigits</vip>
<vip>maxDigits : (<real-domain> RealDomain) -> unsigned MaxDigits</vip>
Line 379: Line 379:
The return maximal number of digits <vp>MaxDigitsNumber</vp> for the ''domainName'' parameter, which should be the name of a <vp>real</vp> domain.
The return maximal number of digits <vp>MaxDigitsNumber</vp> for the ''domainName'' parameter, which should be the name of a <vp>real</vp> domain.


==== not/1 ====
==== not ====


<vip>not : (<term> SubGoal) determ.</vip>
<vip>not : (<term> SubGoal) determ.</vip>
Line 393: Line 393:
The <vp>not</vp> succeeds if <vp>SubGoal</vp> fails when evaluated. Notice that SubGoal cannot bind any variables, because <vp>not(SubGoal)</vp> only succeeds if SubGoal fails (and a failing goal does not bind anything).
The <vp>not</vp> succeeds if <vp>SubGoal</vp> fails when evaluated. Notice that SubGoal cannot bind any variables, because <vp>not(SubGoal)</vp> only succeeds if SubGoal fails (and a failing goal does not bind anything).


==== predicate_fullname/0-> ====
==== predicate_fullname ====


<vip>predicate_fullname : () -> string PredicateFullName.</vip>
<vip>predicate_fullname : () -> string PredicateFullName.</vip>
Line 401: Line 401:
'''Description'''
'''Description'''


<vp>predicate_fullname</vp> can be used only inside clause bodies of a predicate definition. Using of <vp>predicate_fullname</vp> in other places causes a compile time error. See also [[#predicate_name/0->|predicate_name]].
<vp>predicate_fullname</vp> can be used only inside clause bodies of a predicate definition. Using of <vp>predicate_fullname</vp> in other places causes a compile time error. See also [[#predicate_name|predicate_name]].


==== predicate_name/0-> ====
==== predicate_name ====


<vip>predicate_name : () -> string PredicateName.</vip>
<vip>predicate_name : () -> string PredicateName.</vip>
Line 411: Line 411:
'''Description'''
'''Description'''


The <vp>predicate_name</vp> can be used only inside clause bodies of a predicate definition. Using of <vp>predicate_name</vp> in other places causes a compile time error. See also [[#predicate_fullname/0->|predicate_fullname]]
The <vp>predicate_name</vp> can be used only inside clause bodies of a predicate definition. Using of <vp>predicate_name</vp> in other places causes a compile time error. See also [[#predicate_fullname|predicate_fullname]]


==== retract/1 ====
==== retract ====


<vip>retract : (<fact-term> FactTerm) nondeterm anyfow.</vip>
<vip>retract : (<fact-term> FactTerm) nondeterm anyfow.</vip>
Line 437: Line 437:
When retracting a fact, which is declared to be determ, the call to <vp>retract/1</vp> will be deterministic.
When retracting a fact, which is declared to be determ, the call to <vp>retract/1</vp> will be deterministic.


See also [[#retractall/1|retractall/1]] and [[#retractFactDb/1|retractFactDb]].
See also [[#retractall|retractall/1]] and [[#retractFactDb|retractFactDb]].


'''Caution'''
'''Caution'''
Line 445: Line 445:
Be careful calling <vp>retract/1</vp> with free <vp>FactTemplate</vp> variable if any single fact is declared in the project current scope. If you retract a single fact, then the run-time error is generated. The <vp>retract/1</vp> predicate fails when there are no more matches.
Be careful calling <vp>retract/1</vp> with free <vp>FactTemplate</vp> variable if any single fact is declared in the project current scope. If you retract a single fact, then the run-time error is generated. The <vp>retract/1</vp> predicate fails when there are no more matches.


==== retractall/1 ====
==== retractall ====


<vip>retractall : (<fact-term> FactTerm) .</vip>
<vip>retractall : (<fact-term> FactTerm) .</vip>
Line 463: Line 463:
Notice that since it is impossible to retract <vp>single</vp> facts, so the predicate does not retract <vp>single</vp> facts and fact variables, which are defined in matched unnamed facts databases. But notice that, if while compile time the compiler will determ that the only matching fact is some <vp>single</vp> fact, then the compile time error is generated.
Notice that since it is impossible to retract <vp>single</vp> facts, so the predicate does not retract <vp>single</vp> facts and fact variables, which are defined in matched unnamed facts databases. But notice that, if while compile time the compiler will determ that the only matching fact is some <vp>single</vp> fact, then the compile time error is generated.


It is not possible to obtain any output values from <vp>retractall/1</vp>. For this reason, the variables in the call must be bound or be single underscores (anonymous). Notice that  <vp>FactTemplate</vp> can have any level of instantiation, but free variables must be single underscores ("unconditionally anonymous"). In difference to [[#retract/1|retract/1]] "conditionally" anonymous variables with names starting from the underscore (like <vp>_AnyValue</vp>) cannot be used in <vp>retractall/1</vp>.
It is not possible to obtain any output values from <vp>retractall/1</vp>. For this reason, the variables in the call must be bound or be single underscores (anonymous). Notice that  <vp>FactTemplate</vp> can have any level of instantiation, but free variables must be single underscores ("unconditionally anonymous"). In difference to [[#retract|retract/1]] "conditionally" anonymous variables with names starting from the underscore (like <vp>_AnyValue</vp>) cannot be used in <vp>retractall/1</vp>.


See also [[#retract/1|retract/1]] and [[#retractFactDb/1|retractFactDb/1]].
See also [[#retract|retract/1]] and [[#retractFactDb|retractFactDb/1]].


==== retractFactDb/1 ====
==== retractFactDb ====


<vip>retractFactDb : (factDB FactDB).</vip>
<vip>retractFactDb : (factDB FactDB).</vip>
Line 483: Line 483:
Notice, it is impossible to retract <vp>single</vp> facts and fact variables, so the predicate leaves such ones as they are.
Notice, it is impossible to retract <vp>single</vp> facts and fact variables, so the predicate leaves such ones as they are.


See also [[#retractall/1|retractall/1]] and [[#retract/1|retract/1]].
See also [[#retractall|retractall/1]] and [[#retract|retract/1]].


==== retractall/2 ====
==== retractall ====


Obsolete predicate! Use [[#retractFactDb/1|retractFactDb/1]] instead.
Obsolete predicate! Use [[#retractFactDb|retractFactDb/1]] instead.


==== sizeBitsOf/1-> ====
==== sizeBitsOf ====


<vip>sizeBitsOf : (<domain> DomainName) -> unsigned BitSize.</vip>
<vip>sizeBitsOf : (<domain> DomainName) -> unsigned BitSize.</vip>
Line 507: Line 507:
<vip>sizeOfDomain(domain)*8 - 7 <= sizeBitsOf(domain) <= sizeOfDomain(domain)*8</vip>
<vip>sizeOfDomain(domain)*8 - 7 <= sizeBitsOf(domain) <= sizeOfDomain(domain)*8</vip>


See also [[#sizeOfDomain/1->|sizeOfDomain]]/1->.
See also [[#sizeOfDomain|sizeOfDomain]]/1->.


==== sizeOf/1-> ====
==== sizeOf ====


<vip>sizeOf : (<term> Term) -> unsigned ByteSize.</vip>
<vip>sizeOf : (<term> Term) -> unsigned ByteSize.</vip>
Line 523: Line 523:
The <vp>sizeOf/1-></vp> function receives a term as input parameter and returns unsigned value <vp>ByteSize</vp> that specifies the number of bytes occupied in memory by this term <vp>Term</vp>.
The <vp>sizeOf/1-></vp> function receives a term as input parameter and returns unsigned value <vp>ByteSize</vp> that specifies the number of bytes occupied in memory by this term <vp>Term</vp>.


==== sizeOfDomain/1-> ====
==== sizeOfDomain ====


<vip>sizeOfDomain : (<domain> Domain) -> unsigned ByteSize.</vip>
<vip>sizeOfDomain : (<domain> Domain) -> unsigned ByteSize.</vip>
Line 535: Line 535:
<vip>ByteSize = sizeOfDomain(DomainName)</vip>
<vip>ByteSize = sizeOfDomain(DomainName)</vip>


This compiling-time predicate receives the domain <vp>DomainName</vp> as input parameter and return the size of memory that is occupied by the entity of the given domain. The result is measured in bytes. The returned value <vp>ByteSize</vp> belongs to the unsigned domain. Compare with [[#sizeBitsOf/1->|sizeBitsOf/1->]], which returns size of a domain measured in bits.
This compiling-time predicate receives the domain <vp>DomainName</vp> as input parameter and return the size of memory that is occupied by the entity of the given domain. The result is measured in bytes. The returned value <vp>ByteSize</vp> belongs to the unsigned domain. Compare with [[#sizeBitsOf|sizeBitsOf/1->]], which returns size of a domain measured in bits.


==== sourcefile_lineno/0-> ====
==== sourcefile_lineno ====


<vip>sourcefile_lineno : () -> unsigned LineNumber.</vip>
<vip>sourcefile_lineno : () -> unsigned LineNumber.</vip>
Line 547: Line 547:
This compiling-time predicate returns number of line that is currently processed by the compiler in the currently compiled file.
This compiling-time predicate returns number of line that is currently processed by the compiler in the currently compiled file.


==== sourcefile_name/0-> ====
==== sourcefile_name ====


<vip>sourcefile_name : () -> string FileName.</vip>
<vip>sourcefile_name : () -> string FileName.</vip>
Line 557: Line 557:
This compile time predicate returns the string that represents the name of the currently compiled source file
This compile time predicate returns the string that represents the name of the currently compiled source file


==== sourcefile_timestamp/0-> ====
==== sourcefile_timestamp ====


<vip>sourcefile_timestamp : () -> string TimeStamp..</vip>
<vip>sourcefile_timestamp : () -> string TimeStamp..</vip>
Line 579: Line 579:
<vp>SS</vp> - Second.
<vp>SS</vp> - Second.


==== succeed/0 ====
==== succeed ====


<vip>succeed : ().</vip>
<vip>succeed : ().</vip>
Line 589: Line 589:
The standard predicate <vp>succeed/0</vp> succeeds exactly once.
The standard predicate <vp>succeed/0</vp> succeeds exactly once.


==== toBinary/1-> ====
==== toBinary ====


<vip>toBinary : (Term) -> binary Serialized.</vip>
<vip>toBinary : (Term) -> binary Serialized.</vip>
Line 601: Line 601:
<vip>Serialized = toBinary(Term)</vip>
<vip>Serialized = toBinary(Term)</vip>


When a <vp>Term</vp> (of some domain ''domainName'') is converted into a binary, it can safely be stored in a file or sent over a network to another program. Later the obtained binary value <vp>Serialized</vp> can be converted back to a Visual Prolog term, using [[#toTerm/1->|toTerm/1->]] function (the domain for the reversed term should be adequate to ''domainName'') for the reverse conversion.
When a <vp>Term</vp> (of some domain ''domainName'') is converted into a binary, it can safely be stored in a file or sent over a network to another program. Later the obtained binary value <vp>Serialized</vp> can be converted back to a Visual Prolog term, using [[#toTerm|toTerm/1->]] function (the domain for the reversed term should be adequate to ''domainName'') for the reverse conversion.


==== toBoolean/1-> ====
==== toBoolean ====


<vip>toBoolean : (<term> SubGoal) -> boolean Succeed.</vip>
<vip>toBoolean : (<term> SubGoal) -> boolean Succeed.</vip>
Line 617: Line 617:
The <vp>toBoolean/1-></vp> meta-predicate returns [[#boolean|boolean]] value. The result is <vp>true</vp> if ''deterministic_call'' succeeds. The result is <vp>false</vp> if ''deterministic_call'' fails.
The <vp>toBoolean/1-></vp> meta-predicate returns [[#boolean|boolean]] value. The result is <vp>true</vp> if ''deterministic_call'' succeeds. The result is <vp>false</vp> if ''deterministic_call'' fails.


==== toString/1-> ====
==== toString ====


<vip>toString : (Term) -> string Serialized.</vip>
<vip>toString : (Term) -> string Serialized.</vip>
Line 629: Line 629:
<vip>Serialized = toString(Term)</vip>
<vip>Serialized = toString(Term)</vip>


When a <vp>Term</vp> (of some domain ''domainName'') is converted into a string, it can safely be stored in a file or sent over a network to another program. Later the obtained string value can be converted back to a Visual Prolog term, using [[#toTerm/1->|toTerm/1->]] function (the domain of the return value should be adequate to ''domainName'') for the reverse conversion.
When a <vp>Term</vp> (of some domain ''domainName'') is converted into a string, it can safely be stored in a file or sent over a network to another program. Later the obtained string value can be converted back to a Visual Prolog term, using [[#toTerm|toTerm/1->]] function (the domain of the return value should be adequate to ''domainName'') for the reverse conversion.


==== toTerm/1-> ====
==== toTerm ====


<vip>toTerm : (string Serialized) -> Term.
<vip>toTerm : (string Serialized) -> Term.
Line 644: Line 644:
<vip>Term = toTerm(Serialized)</vip>
<vip>Term = toTerm(Serialized)</vip>


The compiler should be able to determine the domain for the returned value <vp>Term</vp> while compiling-time. Notice that binary version of <vp>toTerm</vp> predicate performs almost byte to byte conversion and only checking general compatibility of <vp>Serialized</vp> data with the domain required to the return value <vp>Term</vp>. The programmer is wholly responsible for providing binary data of <vp>Serialized</vp> that can be correctly converted to the term of the desired domain. The <vp>toTerm</vp> predicates are counterparts to predicates [[#toBinary/1->|toBinary/1->]] and [[#toString/1->|toString/1->]]. When a ''Term'' (of some domain ''domainName'') is converted into a binary or string representation <vp>Serialized</vp> (by [[#toBinary/1->|toBinary/1->]] or [[#toString/1->|toString/1->]] correspondingly), it can safely be stored in a file or sent over a network to another program. Later the corresponding <vp>toTerm/1</vp>-> function can convert the obtained string/binary value <vp>Serialized</vp> back to a Visual Prolog term <vp>Term</vp>. For correctness of the reverse conversion the domain of the clause variable <vp>Term</vp> should be adequate to the initial domain ''domainName''.
The compiler should be able to determine the domain for the returned value <vp>Term</vp> while compiling-time. Notice that binary version of <vp>toTerm</vp> predicate performs almost byte to byte conversion and only checking general compatibility of <vp>Serialized</vp> data with the domain required to the return value <vp>Term</vp>. The programmer is wholly responsible for providing binary data of <vp>Serialized</vp> that can be correctly converted to the term of the desired domain. The <vp>toTerm</vp> predicates are counterparts to predicates [[#toBinary|toBinary/1->]] and [[#toString|toString/1->]]. When a ''Term'' (of some domain ''domainName'') is converted into a binary or string representation <vp>Serialized</vp> (by [[#toBinary|toBinary/1->]] or [[#toString|toString/1->]] correspondingly), it can safely be stored in a file or sent over a network to another program. Later the corresponding <vp>toTerm/1</vp>-> function can convert the obtained string/binary value <vp>Serialized</vp> back to a Visual Prolog term <vp>Term</vp>. For correctness of the reverse conversion the domain of the clause variable <vp>Term</vp> should be adequate to the initial domain ''domainName''.


See also [[#tryToTerm/1->|tryToTerm]].
See also [[#tryToTerm|tryToTerm]].


'''Exceptions'''
'''Exceptions'''
Line 654: Line 654:
Run time errors are generated when the <vp>toTerm/1</vp>-> predicate cannot convert the string or binary into a term of the specified domain.
Run time errors are generated when the <vp>toTerm/1</vp>-> predicate cannot convert the string or binary into a term of the specified domain.


==== tryToTerm/1-> ====
==== tryToTerm ====


<vip>tryToTerm : (string Serialized)-> Term determ.
<vip>tryToTerm : (string Serialized)-> Term determ.
tryToTerm : (binary Serialized)-> Term determ.</vip>
tryToTerm : (binary Serialized)-> Term determ.</vip>


Converts the string/binary representation <vp>Serialized</vp> into a term <vp>Term</vp>  like [[#toTerm/1->|toTerm]]. The only difference between the predicates is that <vp>tryToTerm</vp> fails if it cannot convert the string or binary into a term of the specified domain whereas toTerm raises an exception.
Converts the string/binary representation <vp>Serialized</vp> into a term <vp>Term</vp>  like [[#toTerm|toTerm]]. The only difference between the predicates is that <vp>tryToTerm</vp> fails if it cannot convert the string or binary into a term of the specified domain whereas toTerm raises an exception.


See also [[#toTerm/1->|toTerm]].
See also [[#toTerm|toTerm]].


==== tryConvert/2-> ====
==== tryConvert ====


<vip>tryConvert : (<type> Type, Value) determ -> <type> Converted determ.</vip>
<vip>tryConvert : (<type> Type, Value) determ -> <type> Converted determ.</vip>
Line 686: Line 686:
'''Remarks'''
'''Remarks'''


The conversion rules are the same as of the embedded predicate [[#convert/2->|convert/2->]], but <vp>tryConvert/2-></vp> fails when [[#convert/2->|convert/2->]] generates conversion errors.
The conversion rules are the same as of the embedded predicate [[#convert|convert/2->]], but <vp>tryConvert/2-></vp> fails when [[#convert|convert/2->]] generates conversion errors.


This predicate succeeds if the corresponding conversion succeeds. Otherwise it fails. The <vp>tryConvert/2-></vp> predicate tries to perform a clean and genuine conversion of the given <vp>InputTerm</vp> into a value of the specified domain ''returnDomain''. The <vp>tryConvert/2-></vp> predicate will fail if the required conversion cannot be performed. When <vp>tryConvert/2-></vp> predicate succeeds, it returns the term <vp>ReturnTerm</vp> converted to the specified domain ''returnDomain''.
This predicate succeeds if the corresponding conversion succeeds. Otherwise it fails. The <vp>tryConvert/2-></vp> predicate tries to perform a clean and genuine conversion of the given <vp>InputTerm</vp> into a value of the specified domain ''returnDomain''. The <vp>tryConvert/2-></vp> predicate will fail if the required conversion cannot be performed. When <vp>tryConvert/2-></vp> predicate succeeds, it returns the term <vp>ReturnTerm</vp> converted to the specified domain ''returnDomain''.


For allowed conversions and rules of checked explicit conversions see [[#convert/2->|convert/2->]] predicate.
For allowed conversions and rules of checked explicit conversions see [[#convert|convert/2->]] predicate.


See also [[#uncheckedConvert/2->|uncheckedConvert/2->]].
See also [[#uncheckedConvert|uncheckedConvert/2->]].


==== uncheckedConvert/2-> ====
==== uncheckedConvert ====


<vip>uncheckedConvert : (<type> Type, Value) -> <type> Converted.</vip>
<vip>uncheckedConvert : (<type> Type, Value) -> <type> Converted.</vip>
Line 718: Line 718:
The <vp>uncheckedConvert</vp> predicate performs an almost arbitrary conversions.
The <vp>uncheckedConvert</vp> predicate performs an almost arbitrary conversions.


The <vp>uncheckedConvert</vp> predicate performs preliminary evaluation of <vp>InputTerm</vp> (if it is an expression), change current type to ''returnDomain'' type and unifies with <vp>ReturnTerm</vp>. The <vp>uncheckedConvert</vp> predicate performs no runtime checks. It makes only compile time checking of bit-size equality of the converted domains. So almost any term may be quite recklessly converted to any other term. So quite disastrous results may occur if you try to use variables incorrectly converted by <vp>uncheckedConvert</vp>. Be extremely careful implementing <vp>uncheckedConvert</vp>; we strongly recommend you always, when it is possible, using of [[#convert/2->|convert/2->]] and [[#tryConvert/2->|tryConvert/2->]]. But notice that, when an object is returned by COM system it is necessary to convert it by <vp>uncheckedConvert</vp>, as Prolog program does not have information about its actual type.
The <vp>uncheckedConvert</vp> predicate performs preliminary evaluation of <vp>InputTerm</vp> (if it is an expression), change current type to ''returnDomain'' type and unifies with <vp>ReturnTerm</vp>. The <vp>uncheckedConvert</vp> predicate performs no runtime checks. It makes only compile time checking of bit-size equality of the converted domains. So almost any term may be quite recklessly converted to any other term. So quite disastrous results may occur if you try to use variables incorrectly converted by <vp>uncheckedConvert</vp>. Be extremely careful implementing <vp>uncheckedConvert</vp>; we strongly recommend you always, when it is possible, using of [[#convert|convert/2->]] and [[#tryConvert|tryConvert/2->]]. But notice that, when an object is returned by COM system it is necessary to convert it by <vp>uncheckedConvert</vp>, as Prolog program does not have information about its actual type.


==== upperBound/1-> ====
==== upperBound ====


<vip>upperBound : (<numeric-domain> NumericDomain) -> <number-domain> UpperBound.</vip>
<vip>upperBound : (<numeric-domain> NumericDomain) -> <number-domain> UpperBound.</vip>
Line 734: Line 734:
The <vp>upperBound</vp> is a compiling-time predicate. The <vp>upperBound</vp> returns the upper bound value of the specified numeric domain ''domainName''. The return value <vp>UpperBound</vp> belongs to the same domain ''domainName''. The ''domainName'' parameter should be the name of any numerical domain; this domain name should be explicitly specified at compile-time (that is, ''domainName'' cannot come from a variable).
The <vp>upperBound</vp> is a compiling-time predicate. The <vp>upperBound</vp> returns the upper bound value of the specified numeric domain ''domainName''. The return value <vp>UpperBound</vp> belongs to the same domain ''domainName''. The ''domainName'' parameter should be the name of any numerical domain; this domain name should be explicitly specified at compile-time (that is, ''domainName'' cannot come from a variable).


See also [[#lowerBound/1->|lowerBound/1->]].
See also [[#lowerBound|lowerBound/1->]].


'''Exceptions'''
'''Exceptions'''

Revision as of 14:29, 7 November 2008


assert/1 Insert the specified fact at the end of the matched internal facts database.
asserta/1 Insert a fact at the beginning of the matched internal facts database.
assertz/1 Insert a fact at the end of the matched internal facts database.
bound/1 determ Test whether the specified variable is bound to a value.
class_Name/0-> This compile time predicate returns the string ClassName that represents the name of the current interface or class.
compare/2-> Returns the result of the variables' comparison.
convert/2-> Checked term conversion.
digitsOf/1-> Returns precision of the specified floating-point domain.
errorExit/1 erroneous Performs a run-time error with the specified return code ErrorNumber and sets the internal error information.
fail/0 failure Invoke backtracking.
free/1 determ Check whether a variable is free.
hasDomain/2 Checks whether the variable VariableName has the domain domainName.
isErroneous/1 determ Returns the lower bound value of the specified numeric domain.
lowerBound/1-> Returns the lower bound value of the specified numeric domain.
maxDigits/1-> Retrieves the value of digits (precision) of the basic domain corresponding to the specified floating-point domain domainName.
not/1 determ Negate the result (success/fail) of subgoal.
predicate_fullname/1-> This compile time predicate returns the string PredicateFullName that represent the name of the predicate in which clause body predicate_name is called. The returned predicate name is qualified with a scope's name.
predicate_name/0-> This compile time predicate returns the string PredicateName that represents the name of the predicate in which clause body predicate_name is called.
retract/1 nondeterm Remove a matched fact from the matched internal facts database.
retractall/1 Remove all matching facts from the matched internal facts database.
retractFactDb/1 Remove all facts from the specified named internal facts database.
sizeBitsOf/1-> Retrieves the number of bits occupied in memory by an entity of the specified domain DomainName.
sizeOf/1-> Retrieves the number of bytes occupied in memory by the specified term.
sizeOfDomain/1-> Retrieves the number of bytes occupied in memory by the entity of the specified domain DomainName.
sourcefile_lineno/0-> Returns the current line number in the source file processed by the compiler .
sourcefile_name/0-> Returns the name of the source file processed by the compiler.
sourcefile_timestamp/0-> Returns the string representing the date and time of the source file processed by the compiler.
succeed/0 The predicate succeed/0 will always succeed.
toBinary/1-> Converts the specified Term to the binary representation.
toBoolean/1-> The purpose of this meta-predicate is to convert the deterministic call (to a predicate or fact) to the procedure that returns the value of boolean domain.
toString/1-> Converts the specified Term to the string representation.
toTerm/1-> Converts the string/binary representation of the specified term SrcTerm into representation corresponding to the domain of PrologTerm variable of the return value.
tryToTerm/1-> Converts the string/binary representation of the specified term SrcTerm into representation corresponding to the domain of PrologTerm variable of the return value.
tryConvert/2-> determ Checks whether the input term InputTerm can be strictly converted into the specified domain returnDomain and returns the converted term ReturnTerm.
uncheckedConvert/2-> Unchecked conversion of domains.
upperBound/1-> Returns the upper bound value of the specified numeric domain.

The following predicates are deprecated:

finally/2 Use try ... finally ... end try instead.
findall/3 Use list comprehension [ ... || ...  ] instead
trap/3 determ Use try ... catch V do ... end try instead

assert

assert : (<fact-term> FactTerm).

Insert the specified fact at the end of the matched internal facts database

assert(Fact) inserts Fact in the matched internal facts database after any other stored facts for the corresponding database predicate. Fact must be a term belonging to the domain of an internal facts database. assert/1 applied to a single fact changes the existing instance of a fact to the specified one. assert/1 has the same effect as assertz/1. See also asserta/1

Notice that the combination of retract/1 and assert/1 like the following can lead to endless loop:

loop() :-
  retract(fct(X)),
     ...           % creating Y from X
     assert(fct(Y)),
  fail.

The problem is that the retract in first line will eventually retract the fact asserted in the last line, because that fact is inserted last in the fact chain.

Exceptions

Assert to a fact declared as determ, but the fact instance already exists.

asserta

asserta : (<fact-term> FactTerm).

Insert a fact at the beginning of the matched internal facts database.

Description

The asserta(Fact) predicate inserts a Fact in the matched internal facts database before any other stored facts for the corresponding predicate. The Fact must be a term belonging to the domain of an internal facts database. The asserta/1 applied to a single fact changes the existing instance of a fact to the specified one. See also assert/1 and assertz/1.

Exceptions

Assert to a fact declared as determ, but the fact instance already exists.

assertz

assertz : (<fact-term> FactTerm).

assertz does exactly the same as the assert/1 predicate.

bound

bound : (<variable> Variable) determ.

Test whether the specified variable is bound to a value.

Description

The bound(Variable) succeeds if Variable is bound and fails if it is free. The bound predicate is used to control flow patterns and to check the binding of reference variables. The bound predicate treats the specified Variable as bound if any of it's part is instantiated.

See also free/1.

class_Name

class_Name : () -> string ClassName.

This compile time predicate returns the string ClassName that represents the name of the current interface or class.

compare

compare : (A Left, A Right) -> compareResult CompareResult.

Comparison of two terms of the same domain.

Where

CompareResult is the result variable of compareResult domain.

Example

CompareResult = compare("123","abc")

convert

convert : (<type> Type, Term) -> <type> Converted.

Checked term conversion.

Description

Call-template for this function is:

ReturnTerm = convert(returnDomain, InputTerm)

Arguments:

returnDomain: Specifies a domain to which function convert/2-> converts InputTerm. Here returnDomain must be a name of built-in Visual Prolog domain, an interface domain, a name of such user defined domain that is synonym to one of built-in Visual Prolog domains, a numeric domain, binary and pointer domains. The domain name returnDomain must be specified at compile-time, i.e. it cannot come from a variable.

InputTerm: Specifies the value that must be converted. InputTerm may be any Prolog term or an expression. If InputTerm is an expression, then it will be evaluated before the conversion.

ReturnTerm: Returned parameter ReturnTerm will be of returnDomain type.

Remarks

The convert predicate performs a clean and genuine conversion of the given InputTerm, returning a new term ReturnTerm of the specified new domain returnDomain. If convert cannot perform the required conversion, it rises errors. The similar functionality is provided by the tryConvert/2-> predicate, but tryConvert-> fails and does not produce any runtime errors if it cannot perform the conversion.

Allowed conversions:

  • Between numerical domains.
  • Between interface types.
  • Between string and symbol domains.
  • From binary to pointer.
  • For synonyms of mentioned domains.
  • Between reference domains and corresponding non-reference domains.

The contrast to these is uncheckedConvert/2-> predicate, which performs an unchecked conversion between terms from any domains, which have the same bit-size.

The convert/2-> (or tryConvert/2->) predicate accomplishes a checked explicit conversion, when the source and target domains are statically known during the compilation. The result of an explicit conversion can be one of the following:

  • ok the successful conversion to the target domain;
  • run-time-check the conversion to the target domain with generation of run-time checking for compatibility;
  • error the conversion is impossible, error output.

Rules of Checked Explicit Conversions:

  • Synonyms of domains are converted using the same rules that are applied to the domains themselves.
  • Numerical domains can be converted to the numerical domains only.
  • Integral constants are the representatives of the anonymous integral domain: [const .. const].
  • Real constants are the representatives of the anonymous real domain: digits dig [const .. const], where dig is the number of the digits in mantissa without insignificant zeroes.
  • A value of the symbol domain can be converted to the string domain and vice versa.
  • A value of binary domain can be converted to the pointer domain.
  • The domains that are implicitly introduced for interfaces can be converted only to the interface domains according to the rules specified below.
  • All other domains cannot be converted.

Conversions of Numerical Domains:

  • The range is considered first during such conversion. If the ranges of source and target do not intersect, then an error is produced. If the ranges of source and target only partially intersect, then run-time checking is generated. Also, if one of domains is real and another is an integral one, then the integer range is converted to the real range before the comparison.
  • When input term in real and output is integer, then convert/2-> and tryConvert/2-> predicates truncate the input value to the nearest integer value, which is nearer to zero.

Conversions of Interface Types

Predicate convert/2-> allow to convert any object to any interface type. The actual correctness of such conversion is checked at runtime. When object is created, its type is internally stored, therefore when the object is passed as argument it still remember about its original type. This original type is used for checking allowed conversions. The example:

interface x
      supports a, b
end interface x

If object is created by class, which implements x interface, and then object is passed as parameter of type a to some predicate, then it is allowed to convert the object to b type.

Exceptions

  • Check range error.
  • Unsupported interface type.

digitsOf

digitsOf : (<real-domain> Domain) -> unsigned.

Returns precision of the specified floating-point domain.

Description

Call-template for this function is:

Precision = digitsof(domainName)

The input parameter domainName of this compiling-time predicate is a floating-point domain, it should be explicitly specified at compile-time (that is, domainName cannot come from a variable). The predicate returns the number Precision that was determined by the digits attribute in the domain declaration.

The compiler guarantees that values of the domain domainName will have at least Precision number of significant decimal digits.

errorExit

errorExit : (unsigned ErrorNumber) erroneous.

Performs a run-time error with the specified return code ErrorNumber, which can be used in the try-catch-finally.

fail

fail : () failure.

Invoke backtracking

Description

The fail predicate forces failure of a predicate and, hence, always causes backtracking. In a clause ended with fail, it cannot bind output arguments for a clause.

free

free : (<variableName> Variable) determ.

Check whether a variable is free.

Description

Call-template for this predicate is:

free(Variable)

The free predicate succeeds if the specified Variable is free and fails if Variable is bound. The free predicate treats the specified Variable as bound if any of it's part are instantiated.

See also bound/1.

hasDomain

hasDomain : (<type> Type, <variable> Variable) procedure.

Checks whether the variable VariableName has the domain domainName.

Description

Call-template for this predicate is:

hasDomain(domainName, VariableName)

The predicate declares that VariableName that belongs to the domain that is defined by the parameter domainName. The domainName parameter should be the name of a standard or a user defined domain; this domain name should be explicitly specified at compile-time (that is, domainName cannot come from a variable).

lowerBound

lowerBound : (<numeric-domain> NumericDomain) -> <numeric-domain> LowerBound.

Returns the lower bound of the specified NumericDomain.

Description

Call-template for this function is:

LowerBoundValue = lowerBound(domainName)

The lowerBound is a compiling-time predicate. The lowerBound returns the lower bound value LowerBoundValue of the specified numeric domain domainName. The return value LowerBoundValue belongs to the same domain domainName. The domainName parameter should be the name of any numerical domain; this domain name should be explicitly specified at compile-time (that is, domainName cannot come from a variable). See also upperBound/1->.

Exceptions

compile time error if the specified domain domainName is not numeric domain.

isErroneous

isErroneous : (<fact-variable> FactVariable) determ.

The predicate succeeds if the specified fact variable is erroneous.

Description

Call-template for this predicate is:

isErroneous(factVariableName)

The predicate succeeds if the specified fact variable factVariableName has the erroneous value, otherwise it fails.

maxDigits

maxDigits : (<real-domain> RealDomain) -> unsigned MaxDigits

Retrieves the value of digits (precision) of the basic domain corresponding to the specified floating-point domain domainName.

Description

Call-template for this function is:

MaxDigitsNumber = maxdigits(domainName)

The return maximal number of digits MaxDigitsNumber for the domainName parameter, which should be the name of a real domain.

not

not : (<term> SubGoal) determ.

Succeds if the SubGoal fails, and vice versa.

Description

Call-template for this predicate is:

not(SubGoal)

The not succeeds if SubGoal fails when evaluated. Notice that SubGoal cannot bind any variables, because not(SubGoal) only succeeds if SubGoal fails (and a failing goal does not bind anything).

predicate_fullname

predicate_fullname : () -> string PredicateFullName.

This predicate returns the name PredicateFullName of the predicate in which it is invoked. The returned predicate name is qualified with a scope name.

Description

predicate_fullname can be used only inside clause bodies of a predicate definition. Using of predicate_fullname in other places causes a compile time error. See also predicate_name.

predicate_name

predicate_name : () -> string PredicateName.

This predicate returns the name PredicateName of the predicate in which it is invoked.

Description

The predicate_name can be used only inside clause bodies of a predicate definition. Using of predicate_name in other places causes a compile time error. See also predicate_fullname

retract

retract : (<fact-term> FactTerm) nondeterm anyfow.

Successively removes the first matching fact from the facts database. Fails when no more facts match.

Description

Call-template for this predicate is:

retract(FactTemplate)

Here FactTemplate should be a fact term. The retract/1 predicate deletes the first fact that matches the FactTemplate in the appropriated facts database. During backtracking, the rest of the matching facts will be deleted.

Notice that FactTemplate can have any level of instantiation. The FactTemplate is matched with the facts in the facts database, which means that any free variables will be bound in the call to retract/1.

The FactTemplate can contain any anonymous variables. That is, variables with names consisting from the single underscore _ or a variable with a name starting with an underscore _AnyValue if the variable occurs only once in the clause. For example.

retract(person("Hans", _Age)),

will retract the first matched person fact that has "Hans" as the first argument and anything as the second argument.

When retracting a fact, which is declared to be determ, the call to retract/1 will be deterministic.

See also retractall/1 and retractFactDb.

Caution

The retract/1 predicate cannot be applied to single facts or fact variables.

Be careful calling retract/1 with free FactTemplate variable if any single fact is declared in the project current scope. If you retract a single fact, then the run-time error is generated. The retract/1 predicate fails when there are no more matches.

retractall

retractall : (<fact-term> FactTerm) .

Remove all matching facts from the facts database.

Description

Call-template for this predicate is:

retractall(FactTemplate)

Here FactTemplate should be a fact term.

The retractall/1 retracts all matching facts (for facts database predicates in unnamed facts databases) which match the given FactTemplate. It always succeeds, even if there were no facts to retract.

Notice that since it is impossible to retract single facts, so the predicate does not retract single facts and fact variables, which are defined in matched unnamed facts databases. But notice that, if while compile time the compiler will determ that the only matching fact is some single fact, then the compile time error is generated.

It is not possible to obtain any output values from retractall/1. For this reason, the variables in the call must be bound or be single underscores (anonymous). Notice that FactTemplate can have any level of instantiation, but free variables must be single underscores ("unconditionally anonymous"). In difference to retract/1 "conditionally" anonymous variables with names starting from the underscore (like _AnyValue) cannot be used in retractall/1.

See also retract/1 and retractFactDb/1.

retractFactDb

retractFactDb : (factDB FactDB).

Remove all facts from the named internal facts database FactDB.

Description

Call-template for this predicate is:

retractFactDb(FactDB)

The retractFactDb/1 removes all facts from the named facts database FactDB.

Notice, it is impossible to retract single facts and fact variables, so the predicate leaves such ones as they are.

See also retractall/1 and retract/1.

retractall

Obsolete predicate! Use retractFactDb/1 instead.

sizeBitsOf

sizeBitsOf : (<domain> DomainName) -> unsigned BitSize.

Retrieves the number of bits occupied in memory by an entity of the specified domain DomainName.

Description

Call-template for this function is:

BitSize = sizeBitsOf(DomainName)

This compiling-time predicate receives the domain DomainName as input parameter and return the size of memory that is occupied by the entity of the given domain. The result is measured in bits. For the integer domains sizeBitsOf/1-> predicate returns the value that was defined for the size-field in a domain's declaration.

The following is always true for the integral domains:

sizeOfDomain(domain)*8 - 7 <= sizeBitsOf(domain) <= sizeOfDomain(domain)*8

See also sizeOfDomain/1->.

sizeOf

sizeOf : (<term> Term) -> unsigned ByteSize.

Retrieves the number of bytes occupied in memory by the specified term Term.

Description

Call-template for this function is:

ByteSize = sizeOf(Term)

The sizeOf/1-> function receives a term as input parameter and returns unsigned value ByteSize that specifies the number of bytes occupied in memory by this term Term.

sizeOfDomain

sizeOfDomain : (<domain> Domain) -> unsigned ByteSize.

Retrieves the number of bytes occupied in memory by the entity of the specified domain DomainName.

Description

Call-template for this function is:

ByteSize = sizeOfDomain(DomainName)

This compiling-time predicate receives the domain DomainName as input parameter and return the size of memory that is occupied by the entity of the given domain. The result is measured in bytes. The returned value ByteSize belongs to the unsigned domain. Compare with sizeBitsOf/1->, which returns size of a domain measured in bits.

sourcefile_lineno

sourcefile_lineno : () -> unsigned LineNumber.

Returns the current line number in the source file processed by the compiler.

Description

This compiling-time predicate returns number of line that is currently processed by the compiler in the currently compiled file.

sourcefile_name

sourcefile_name : () -> string FileName.

Returns the name of the source file processed by the compiler.

Description

This compile time predicate returns the string that represents the name of the currently compiled source file

sourcefile_timestamp

sourcefile_timestamp : () -> string TimeStamp..

Returns the string representing the date and time of the source file processed by the compiler.

Description

This compile time predicate returns the string that represents the date and time marks of the currently compiled source file in format of YYYY-MM-DD HH:MM:SS. Where:

YYYY - Year.

MM - Month.

DD - Day.

HH - Hour.

MM - Minute.

SS - Second.

succeed

succeed : ().

The predicate succeed/0 will always succeed.

Description

The standard predicate succeed/0 succeeds exactly once.

toBinary

toBinary : (Term) -> binary Serialized.

Converts the specified Term to binary representation.

Description

Call-template for this function is:

Serialized = toBinary(Term)

When a Term (of some domain domainName) is converted into a binary, it can safely be stored in a file or sent over a network to another program. Later the obtained binary value Serialized can be converted back to a Visual Prolog term, using toTerm/1-> function (the domain for the reversed term should be adequate to domainName) for the reverse conversion.

toBoolean

toBoolean : (<term> SubGoal) -> boolean Succeed.

The purpose of this meta-predicate is to convert the deterministic call (to a predicate or fact) to the procedure that returns the value of boolean domain.

Description

Call-template for this meta-predicate is:

True_or_False = toBoolean(deterministic_call)

The toBoolean/1-> meta-predicate returns boolean value. The result is true if deterministic_call succeeds. The result is false if deterministic_call fails.

toString

toString : (Term) -> string Serialized.

Converts the specified Term to string representation.

Description

Call-template for this function is:

Serialized = toString(Term)

When a Term (of some domain domainName) is converted into a string, it can safely be stored in a file or sent over a network to another program. Later the obtained string value can be converted back to a Visual Prolog term, using toTerm/1-> function (the domain of the return value should be adequate to domainName) for the reverse conversion.

toTerm

toTerm : (string Serialized) -> Term.
toTerm : (binary Serialized) -> Term.

Converts the string/binary representation of the specified term Serialized into representation corresponding to the domain of PrologTerm variable of the return value.

Description

Call-template for this function is:

Term = toTerm(Serialized)

The compiler should be able to determine the domain for the returned value Term while compiling-time. Notice that binary version of toTerm predicate performs almost byte to byte conversion and only checking general compatibility of Serialized data with the domain required to the return value Term. The programmer is wholly responsible for providing binary data of Serialized that can be correctly converted to the term of the desired domain. The toTerm predicates are counterparts to predicates toBinary/1-> and toString/1->. When a Term (of some domain domainName) is converted into a binary or string representation Serialized (by toBinary/1-> or toString/1-> correspondingly), it can safely be stored in a file or sent over a network to another program. Later the corresponding toTerm/1-> function can convert the obtained string/binary value Serialized back to a Visual Prolog term Term. For correctness of the reverse conversion the domain of the clause variable Term should be adequate to the initial domain domainName.

See also tryToTerm.

Exceptions

Compile time error if the compiler cannot determ the return value domain.

Run time errors are generated when the toTerm/1-> predicate cannot convert the string or binary into a term of the specified domain.

tryToTerm

tryToTerm : (string Serialized)-> Term determ.
tryToTerm : (binary Serialized)-> Term determ.

Converts the string/binary representation Serialized into a term Term like toTerm. The only difference between the predicates is that tryToTerm fails if it cannot convert the string or binary into a term of the specified domain whereas toTerm raises an exception.

See also toTerm.

tryConvert

tryConvert : (<type> Type, Value) determ -> <type> Converted determ.

Checks whether the input term InputTerm can be strictly converted into the specified domain Type and returns the converted term Converted.

Description

Call-template for this function is:

ReturnTerm = tryConvert(returnDomain, InputTerm)

Arguments:

returnDomain: Specifies a domain to which tryConvert/2-> predicate tries to convert the specified InputTerm. Here returnDomain can be any domain accessible in the current scope. The domain name returnDomain must be specified at compile-time, i.e. it cannot come from a variable.

InputTerm: Specifies the term that must be converted. InputTerm may be any Prolog term or an expression. If InputTerm is an expression, then it will be evaluated before conversion.

ReturnTerm: Returned term ReturnTerm will be of returnDomain domain.

Remarks

The conversion rules are the same as of the embedded predicate convert/2->, but tryConvert/2-> fails when convert/2-> generates conversion errors.

This predicate succeeds if the corresponding conversion succeeds. Otherwise it fails. The tryConvert/2-> predicate tries to perform a clean and genuine conversion of the given InputTerm into a value of the specified domain returnDomain. The tryConvert/2-> predicate will fail if the required conversion cannot be performed. When tryConvert/2-> predicate succeeds, it returns the term ReturnTerm converted to the specified domain returnDomain.

For allowed conversions and rules of checked explicit conversions see convert/2-> predicate.

See also uncheckedConvert/2->.

uncheckedConvert

uncheckedConvert : (<type> Type, Value) -> <type> Converted.

Unchecked conversion of a value to another type.

Description

Call-template for this function is:

ReturnTerm = uncheckedConvert(returnDomain, InputTerm)

Arguments:

returnDomain: Specifies a domain to which uncheckedConvert predicate unsafely converts the specified InputTerm. Here returnDomain can be any domain accessible in the current scope, the ReturnTerm should has the same bit-size as the InputTerm. The domain name returnDomain must be specified at compile-time, i.e. it cannot come from a variable.

InputTerm: Specifies the value that must be converted. InputTerm may be any Prolog term or an expression. If InputTerm is an expression, then it will be evaluated before conversion.

ReturnTerm: Returned parameter ReturnTerm will be of returnDomain type.

Remarks

The uncheckedConvert predicate performs an almost arbitrary conversions.

The uncheckedConvert predicate performs preliminary evaluation of InputTerm (if it is an expression), change current type to returnDomain type and unifies with ReturnTerm. The uncheckedConvert predicate performs no runtime checks. It makes only compile time checking of bit-size equality of the converted domains. So almost any term may be quite recklessly converted to any other term. So quite disastrous results may occur if you try to use variables incorrectly converted by uncheckedConvert. Be extremely careful implementing uncheckedConvert; we strongly recommend you always, when it is possible, using of convert/2-> and tryConvert/2->. But notice that, when an object is returned by COM system it is necessary to convert it by uncheckedConvert, as Prolog program does not have information about its actual type.

upperBound

upperBound : (<numeric-domain> NumericDomain) -> <number-domain> UpperBound.

Returns the upper bound value of the specified numeric domain.

Description

Call-template for this function is:

UpperBound = upperBound(domainName)

The upperBound is a compiling-time predicate. The upperBound returns the upper bound value of the specified numeric domain domainName. The return value UpperBound belongs to the same domain domainName. The domainName parameter should be the name of any numerical domain; this domain name should be explicitly specified at compile-time (that is, domainName cannot come from a variable).

See also lowerBound/1->.

Exceptions

compile time error if the specified domain domainName is not numeric domain.