assertz(
Fact)
Stores the fact Fact to the end of the database.
Example:
assertz(connection(7588, 9032))
bound(
Var)
Succeeds, if the parameter Var is bound, otherwise fails.
comline_arg(
Number,
Option,
Argument)
Not implemented like other built-in predicates. Instead, each command line argument is stored to the database as a separate fact.
Returns information about one command line argument, if one can be found.
A command line example:
> java -jar jalog.jar myprogram.pro -foo=bar -up report.txt
Note the equal sign separating an option and its argument.
Parameters of this command line are stored to the database prior to starting
myprogram.pro
as following facts:
comline_arg(1, "foo", "bar"). comline_arg(2, "up", ""). comline_arg(3, "", "report.txt").
consult(
Filename)
Reads the facts and rules to the database and executes the goals from the file Filename.
Example:
consult("route_data.pro")
dynamic(
PredicateIndicator)
Prevents an error message, if no clause matching PredicateIndicator is found in the database. This is intended for predicates that can be asserted and retracted in runtime. This is intended to be used as a directive.
A PredicateIndicator must be a string of form
Functor/
Arity .
Example:
:- dynamic("route/3").
exit
Terminates the program with exit code 0
.
However, if exit is called (typically very indirectly) in
execution of the first argument of trap
then control
is transferred to the trap
predicate.
exit(
Int_value)
Terminates the program with exit code Int_value.
However, if exit is called (typically very indirectly) in
execution of the first argument of trap
then control
is transferred to the trap
predicate.
fail
This call fails always.
foreach_(
Var,
List
)
Binds the first variable Var in the first call to the first item of the list List in the second variable, and in recalls to the succeeding items.
foreach_(X, [1, 2, 3]), write(' ', X), fail.
prints
1 2 3
is_char(
Var)
Succeeds, if the parameter Var is bound to a character value.
is_compound(
Var)
Succeeds, if the parameter Var is bound to a compound structure.
is_integer(
Var)
Succeeds, if the parameter Var is bound to an integer value.
is_list(
Var)
Succeeds, if the parameter Var is bound to a list structure.
is_real(
Var)
Succeeds, if the parameter Var is bound to a real value.
is_string(
Var)
Succeeds, if the parameter Var is bound to a string value.
nl
Prints a newline character.
not(
Predicate_call)
Fails, if Predicate_call succeeds, succeeds, if Predicate_call fails.
Example:
not(connection(7588, 9032))
fails, if
connection(7588, 9032)
is found from the database, otherwise
succeeds.
trap(
Predicate_call,
Var_exit,
Exception_handler)
Executes Predicate_call. If an exception happens or exit
is called
within the call, the exit code is bound to Var_exit,
Exception_handler is called, and finally the whole trap
predicate fails.
Example:
trap(analyze(Situation, Results), X, write("*** Exception ", X, '!'))
write(
parameters)
Prints the values of the parameters without punctuation or whitespace in between.
write('a', "bc", 3.142)
prints abc3.142
writeln(
parameters)
As write
but followed by nl
writeq(
parameters)
Prints the values of the parameters in lexical notation so that they can be read back. Strings are enclosed in double quotes and characters are enclosed in single quotes.
writeq('a', "bc", 3.142)
prints 'a'"bc"3.142
writeq(a('b', 'c'))
prints a('b','c')
Arithmetic operators have their normal precedences. Expressions in
parenthesis ()
are evaluated first. Operators multiplication,
division, mod
, and div
have the same precedence
and are evaluated from left to right.
Symbol | Operation | Left Type | Right Type | Result Type | Example | Example Value |
---|---|---|---|---|---|---|
* |
multiplication | integer | integer | integer | 2 * 3 |
6 |
* |
multiplication | integer | real | real | 2 * 3.2 |
6.4 |
* |
multiplication | real | integer | real | 2.2 * 3 |
6.6 |
* |
multiplication | real | real | real | 2.2 * 3.2 |
7.04 |
/ |
division | integer | integer | real | 3 / 2 |
1.5 |
/ |
division | integer | real | real | 4 / 2.5 |
1.6 |
/ |
division | real | integer | real | 6.8 / 4 |
1.7 |
/ |
division | real | real | real | 14.7 / 4.2 |
3.5 |
div |
integer division | integer | integer | integer | 5 div 3 |
1 |
mod |
remainder | integer | integer | integer | 5 mod 3 |
2 |
+ |
addition | integer | integer | integer | 2 + 3 |
5 |
+ |
addition | integer | real | real | 2 + 3.2 |
5.2 |
+ |
addition | real | integer | real | 2.2 + 3 |
5.2 |
+ |
addition | real | real | real | 2.2 + 3.2 |
5.4 |
- |
subtraction | integer | integer | integer | 3 - 2 |
1 |
- |
subtraction | integer | real | real | 3 - 2.2 |
0.8 |
- |
subtraction | real | integer | real | 3.2 - 2 |
1.2 |
- |
subtraction | real | real | real | 3.2 - 2.2 |
1.0 |
+ |
identity function | integer | integer | + 3 |
3 | |
+ |
identity function | real | real | + 3.2 |
3.2 | |
- |
negation | integer | integer | - 2 |
-2 | |
- |
negation | real | real | - 2.2 |
-2.2 |