package com.franz.ag.examples;
import com.franz.ag.*;
public class AGEvalInServer {
/**
* Demonstrates some basics of evaluating lisp in the server.
*
* To run this and other examples that use evalInServer, you will need
* to start the server using the --eval-in-server-file option. See the
* instructions on starting a server manually for an example of this.
*
* Note that this is an advanced feature for users that understand the
* internals of the AllegroGraph server. The purpose of this example
* is simply to convey that one can indeed command the server in lisp
* through the Java API.
*
* @param args unused
* @throws AllegroGraphException
*/
public static void main(String[] args) throws AllegroGraphException {
// Connect to server, which must already be running.
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
// Add two numbers in the server and show the result
evalInServer("(+ 2 3)",ags);
// Define and call a function to add two numbers
evalInServer("(defun foo (x y) (+ x y))",ags);
evalInServer("(foo 4 5)",ags);
// You can send a sequence of commands in a single call
evalInServer("(progn (defun bar (x y) (+ x y)) (bar 6 7))",ags);
// Symbols do not come back from the server
evalInServer("'a",ags);
// Disconnect from the server
ags.disable();
}
private static void evalInServer(String lispexpr, AllegroGraphConnection ags) throws AllegroGraphException {
AGUtils.printObjectArray("Server> "+ lispexpr, ags.evalInServer(lispexpr));
}
}