Embed MINERVA in your Java programs:
See also the javadoc style documentation.
If you only want to extend MINERVA with some Java classes/methods, then we recommend to use the MINERVA Extender minervax. This tools also allows to generate a new main program, which shows how to activate MINERVA.
If you want to use the class Minerva as a kind of thread not in charge of user interaction, for example because you prefer to use a GUI written with some other tool, then you can instantiate the class Minerva directly, invoke and obtain results with its method execute.
At instantiation time take care to supply the needed parameters; see the minerva* scripts for examples. If you invoke MINERVA from an applet you must also supply the reference to the applet.
The class Minerva knows two constructors:
public Minerva(String[] args)
public Minerva(Applet applet, String[] args)
The former is for convenience, it simply calls Minerva(null,args). Use the second one for invokation from an applet.
Example:
public class Test extends Applet {
Minerva minerva = null;
...
public void start() {
String args = new String[2];
args[0] = "-c";
args[1] = "/minerva/minervagui.mca";
minerva = new Minerva(this, args);
...
}
...
}
The interface from Java to MINERVA knows the following classes. (Abstract methods of the superclasses are of course defined in the subclasses but are not again listed there.)
abstract class MinervaTerm {
public static final int VARIABLE = 0;
public static final int ATOM = 1;
public static final int LONG = 2;
public static final int DOUBLE = 3;
public static final int OBJECT = 4;
public static final int COMPOUND = 5;
public static final int LIST = 6;
// returns the type of a term
abstract public int typeOf();
// returns the identic term where every variable is replaced
// with its associated term. The term itself is not modified.
public MinervaTerm resolve() {
// equality of two terms
abstract public boolean equals(Object other);
// returns hashCode for the term
abstract public int hashCode();
// returns a textual representation of a String
abstract String toString();
}
public class MinervaAtom extends MinervaTerm {
// create an atom of the name 'name'
public MinervaAtom(String name);
// returns the string associated with the atom
public String stringValue();
}
public abstract class MinervaNumber extends MinervaTerm {
// returns the value as an integer
abstract long longValue();
// returns the value as a real
abstract double doubleValue();
}
public class MinervaLong extends MinervaNumber {
public MinervaLong(long value);
}
public class MinervaDouble extends MinervaNumber {
public MinervaDouble(double value);
}
public class MinervaObject extends MinervaNumber {
public MinervaObject(Object object);
// returns the Object associated with a term
public Object objectValue();
}
public class MinervaVariable extends MinervaNumber {
public MinervaVariable();
// sets the term that the variable shall be associated with
public void setValue(MinervaTerm term);
// enquire for the term associated with the variable.
// NOTE: the method returns null if there is no term associated
public MinervaTerm getValue();
}
public abstract class MinervaStruct extends MinervaTerm {
// return functor
abstract String getFunctor();
// return arity
abstract int getArity();
// return the i-th argument (0 <= i < getArity())
abstract MinervaTerm getArg(int i);
// associate a term with the i-th argument
abstract void setArg(int i, MinervaTerm term);
}
public class MinervaCompound extends MinervaStruct {
// create functor(args[0], ... args[args.length])
public MinervaCompound(String functor, MinervaTerm[] args);
// create a compound term. All arguments are initialized to null.
// I.e. YOU HAVE to initialize them with setArg()
public MinervaCompound(String functor, int arity);
// create a unary compound: functor(a1)
public MinervaCompound(String functor, MinervaTerm a1);
public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2);
public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3);
public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3, MinervaTerm a4);
public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3, MinervaTerm a4, MinervaTerm a5);
public MinervaCompound(String functor, MinervaTerm a1, MinervaTerm a2, MinervaTerm a3, MinervaTerm a4, MinervaTerm a5, MinervaTerm a6);
}
public class MinervaList extends MinervaStruct {
// construct a list: [head|tail]
public MinervaList(MinervaTerm head, MinervaTerm tail);
// construct a list. Head and Tail of the list are initialized with null
// i.e. YOU HAVE to initialize with setArg(), setHead(), setTail()
public MinervaList();
// returns the head of a list
public MinervaTerm getHead();
// returns the tail of a list
public MinervaTerm getTail();
// sets the head of a list
public void setHead(MinervaTerm term);
// sets the tail of a list
public void setTail(MinervaTerm term);
// returns an enumerator for the list.
// With the enumerator it is easy to operate on all elements
// of a list (cf index of an array)
public Enumeration getEnumeration();
}
The following desribes the invocation interface of MINERVA from Java. The methods execute expect objects of type MinervaTerm. The methods execute can return results to Java.
When execute is called successfully, all objects of type MinervaVariable are associated (setValue()) with the terms they are unified with at exit time of the call.
Example:
import com.ifcomputer.minerva.*;
public class Test {
private static MinervaTerm makeChar(char c) { return new MinervaAtom(String.valueOf(c)); }
private static MinervaTerm makeList(String s) { MinervaTerm list = new MinervaAtom("[]"); for ( int i = s.length()-1; i >= 0; --i ) list = new MinervaList(makeChar(s.charAt(i)), list); return list; }
public static void main(String args[]) throws Exception { Minerva minerva = new Minerva(args); MinervaVariable v = new MinervaVariable(); MinervaTerm l1 = makeList("abc"); MinervaTerm l2 = makeList("def"); if ( minerva.execute("append", l1, l2, v) ) { System.out.println("append("+l1+", "+l2+") = "+v.getValue()); } else { System.out.println("execution failed"); } } }