Jalog 1.1
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")
consult_data(
Filename,
Filter)
Reads the facts to the database from the file Filename. Only facts specified in the Filter are consulted. Filter is a list of strings, each containing a predicate indicator in form name/arity .
Example:
consult_data("data.pro", ["cars/4", "houses/2"])
consult_dir(
Dirname)
If Dirname is bound to a string sets current consult directory.
If Dirname is open it will be bound to the current
consult directory name. The directory name is absolute and always begins with
"file:
" or "res:
". It can be used as an argument to
set_consult_dir
.
Examples:
"file:C:/data"
- refers to the data directory at the root of
the C disk.
"res:lib/routes"
- refers to a resource directory.
"sub"
- refers to the subdirectory sub
of
the current directory.
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
free(
Var)
Succeeds, if the parameter Var is open, otherwise fails.
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')
=
RightTries to unify Left and Right.
>
Right>=
Right<
Right<=
Right!=
RightCompares arithmetically or lexicographically Left and Right.
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 |
file:
". In order to refer to a directory in the resource system
prepend the name with "res:
". If neither is specified and the
dirname is an absolute path it refers to the file system. A relative path
refers to a subdirectory of the current consult directory.
"file:C:/data"
- refers to the data directory at the root of
the C disk."res:lib/routes"
- refers to a resource directory."sub"
- refers to the subdirectory sub
of
the current directory.file:
". In order to refer to a resource in the resource system
prepend the name with "res:
". If neither is specified and the
filename is an absolute path it refers to the file system. A relative path
refers to a file or resource in the current consult directory.
"file:C:/data/trees.pro"
- refers to a file in the file
system.
"res:parameters.pro"
- refers to a resource in the resource system.
"rules.pro"
- refers to a file or a resource in the current
directory.