Jalog 1.4
assert(
Fact)
Stores the fact Fact to the end of the database. Same as assertz
.
Example:
assert(connection(7588, 9032))
asserta(
Fact)
Stores the fact Fact to the beginning of the database.
Example:
asserta(address("Sqrt", $082A))
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").
concat(
String1, String2, LongString)
Obtains LongString by concatenating String1 and String2
Example:
concat(S, ".pro", Filename)
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.
findall(
Variable, Atom, ListVariable)
Collects the values from backtracking into a list. Thus, if Atom is a predicate with its arguments represented by valid variable names, and Variable is the name of one of the variables in the predicate, ListVariable will be bound to the list of values for that variable that was obtained from instances when the predicate can succeed due to backtracking.
Example:
findall(P, substring("a, b, c, d", P, _, ","), L)
L
will contain the positions of commas:
[1, 4, 7]
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.
frontchar(
String, FrontChar, RestString)
Isolates the first character of String.
frontstr(
NumberOfChars, String1, StartStr, String2)
Splits String1 into two parts. StartStr will contain the first NumberOfChars characters in String1 and String2 will contain the rest.
fronttoken(
String, Token, RestString)
Isolates the first token of String. Whitespace in front of the token is skipped.
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.
isname(
StringParam)
Succeeds, if StringParam is a name.
member(
Elem, List)
If Elem
is bound, succeeds if Elem
is a member of List
. If Elem
is free, picks one element of List
and on backtracking next elements one by one, and fails at the end of List
.
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.
retract(
Fact)
Deletes the first fact in the database that matches the given Fact. The argument cannot be open. It must be a compound that can have open arguments.
Example:
retract(route("Moscow", _))
retractall(
Fact)
Deletes all facts in the database that match the given Fact. The argument cannot be open. It must be a compound that can have open arguments.
Example:
retractall(route("Moscow", _))
searchchar(
Text,
Character,
Position)
Searches Character in Text. The first call finds the first Position. Each recall finds the next Position as long as there are any. Fails when no more found.
Example:
searchchar("A-B+C-D", '-', P).
Returns P
= 1 on first call. If backtracked returns P
= 5. If backtracked again fails.
searchstring(
Text,
String,
Position)
Searches String in Text. The first call finds the first Position. Each recall finds the next Position as long as there are any. Fails when no more found.
Example:
searchstring("Apple,, Banana, Orange", ",,", P).
Returns P
= 5 on first call. If backtracked fails.
str_char(
StringParam,
CharParam)
One of the parameters must be bound. Converts the bound parameter to other type. If both parameters are bound succeeds if both parameters are equivalent.
Example:
str_char("A", 'A').
Succeeds
str_int(
StringParam,
IntParam)
One of the parameters must be bound. If StringParam is bound it must be a decimal integer (possibly preceded by a minus sign). Converts the bound parameter to other type. If both parameters are bound succeeds if both parameters are equivalent.
Example:
str_int("-32768", -32768).
Succeeds
str_len(
String,
Length)
Length is set to number of characters in the String.
Example:
str_len("Very long string", Len).
Sets Len
to 16.
substring(
LongString,
Pos,
Len,
SubString)
The parameter LongString must be bound to a string.
If Pos and Len are bound then Substring is bound to part of LongString that starts at Pos and is Len characters long.
if Pos is bound and Substring is bound and Len is open or bound to the length of Substring then SubString is searched in LongString. The first call finds the first Pos. Each recall finds the next Pos as long as there are any. The predicate fails when no more found.
Example:
substring("Programs/Games/Chess.exe", 9, 5, S).
Returns S
= "Games"
.
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, '!'))
upper_lower(
StringInUpperCase,
StringInLowerCase)
One of the parameters must be bound.
If only StringInUpperCase is bound then converts the string to lower case and binds it to StringInLowerCase.
If only StringInLowerCase is bound then converts the string to upper case and binds it to StringInupperCase.
If both parameters are bound compares parameters ignoring the case, and fails if they are not equivalent.
Example:
upper_lower("String", A).
Returns A
= "string"
write(
parameters)
Prints the values of the parameters without punctuation or whitespace in between.
Example:
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.
Examples:
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.