java.lang.Object io.github.JalogTeam.jalog.Jalog
public class Jalog
Class Jalog
represents the Prolog subsystem.
Before running the Prolog program the Prolog subsystem is instantiated.
Running the system can consist of several calls.
Each call is preceded by construction of input and output data structures.
Then the instantiated system is used to run the program.
The run call should be within a try-catch structure, because it can throw
an exception.
If the call succeeds, the results are recovered from the Prolog data structures.
Finally the subsystem is disposed.
Typical calling pattern:
static Jalog myJalog = new Jalog(); myJalog.consult_file("source.pro"); /* for each call */ /* construct data structures, e.g.: */ Jalog.Term count = Jalog.integer(7); Jalog.Term answer = Jalog.open(); /* call the predicate */ try { if (myJalog.call("predicate", count, answer)) { /* success */ if (answer.getType() == Jalog.INTEGER) { /* answer of expected type got */ long result = answer.getIntegerValue(); } else { /* wrong type, should not occur */ } } else { /* predicate failed */ } } catch (Jalog.Exit e) { /* exception */ } /* when everything is done */ myJalog.dispose();
Nested Class Summary | |
---|---|
static class |
Jalog.Term
All data processed and produced by Jalog is of this class. |
static class |
Jalog.Exit
Exception to be raised when exit predicate is executed. |
Field Summary | |
---|---|
static String |
CHARACTER
Code for character variable. |
static String |
COMPOUND
Code for compound variable. |
static String |
INTEGER
Code for integer variable. |
static String |
LIST
Code for list variable. |
static String |
OPEN
Code for open variable. |
static String |
REAL
C ode for real variable. |
static String |
STRING
Code for string variable. |
static String |
SYMBOL
Code for symbol variable. |
Constructor Summary | |
---|---|
Jalog()
Constructs a Jalog engine instance. |
Method Summary | |
---|---|
static boolean
|
call(String predname, Jalog.Term ... args)
Calls a predicate defined in the consulted file. |
static Jalog.Term
|
character(char c)
Creates a new character term with value c. |
static Jalog.Term
|
compound(String name, Jalog.Term[] arguments)
Creates a new compound term with functor name name and
components from arguments array. If the arguments array is empty, the result
is of type symbol.
|
static void
|
consult_file(String filename)
Consults (reads and compiles) a Prolog source file. |
static void
|
dispose()
Clears the database of program and data.. |
static Jalog.Term
|
integer(long i)
Creates a new integer term with value i. |
static Jalog.Term
|
list(Jalog.Term[] elements)
Creates a new list term populated with items from elements
|
static Jalog.Term
|
open()
Creates a new open variable. |
static Jalog.Term
|
real(double r)
Creates a new real term with value r. |
static void
|
set_comline_arg
(String option, String argument)
Defines a command-line argument for the Jalog program. |
static Jalog.Term
|
string(String s)
Creates a new string term with value s. |
static Jalog.Term
|
symbol(String name)
Creates a new symbol term with value name. |
Field Detail |
---|
public static final String OPEN = "open"
public static final String INTEGER = "integer"
public static final String SYMBOL = "symbol"
public static final String REAL = "real"
public static final String CHARACTER = "character"
public static final String STRING = "string"
public static final String LIST = "list"
public static final String COMPOUND = "compound"
Constructor Detail |
---|
public Jalog()
Jalog
inference engine. Limitation: Only one
engine can exist at any time. After usage it must be disposed of using
the dispose method.
Error
- if a Jalog inference engine already exists.
dispose()
Method Detail |
---|
public static Jalog.Term open()
public static Jalog.Term integer(long i)
i
- the value of the new integer.
public static Jalog.Term symbol(String name)
name
- the value of the new symbol.
public static Jalog.Term real(double r)
r
- the value of the new real.
public static Jalog.Term character(char c)
c
- the value of the new character.
public static void set_comline_arg(String option, String argument)
option
- the name of the option.argument
- the value of the option. -foo=bar -up report.txt
set_comline_arg("foo", "bar");
set_comline_arg("up", "");
set_comline_arg("", "report.txt");
comline_arg(1, "foo", "bar").
comline_arg(2, "up", "").
comline_arg(3, "", "report.txt").
public static Jalog.Term string(String s)
s
- the value of the new string.
public static Jalog.Term list(Jalog.Term[] elements)
elements
array.
elements
- the items of the new list.
public static Jalog.Term compound(String name, Jalog.Term[] arguments)
name
and
components from arguments array. If the arguments array is empty, the result
is of type symbol.
name
- the functor of the new compound.arguments
- the components of the new compound.public static void consult_file(String filename)
filename
- the name of the Prolog source file.public static void dispose()
public static boolean call(String predname, Jalog.Term ... args)
predname
- the name of the predicate to be called.
args
- the arguments for the predicate.
true
if the predicate succeeds, false
if the
predicate fails.
Jalog.Exit
- when the program executes an exit predicate.