[armedbear-devel] How to compile and run Maxima with ABCL?

Robert Dodier robert.dodier at gmail.com
Tue Jun 19 03:04:09 UTC 2012


On 2012-06-16, Phuc Luoi <phucluoi at gmail.com> wrote:

> How can I compile and run Maxima with ABCL?

(1) Unpack a Maxima tarball.
http://sourceforge.net/projects/maxima and follow links to download page.
Look for "Maxima-source".

(2) cd /path/to/maxima-5.27.0

(3) java -jar /path/to/abcl.jar

(4) (configure) ;; you can probably accept defaults for most/all questions

(5) (quit)

(6) cd src

(7) java -jar /path/to/abcl.jar

(8) (require 'asdf)

(9) (asdf:operate 'asdf:load-op :maxima)

(10) (quit)

(11) java -jar /path/to/abcl.jar

(12) (require 'asdf)

(13) (asdf:operate 'asdf:load-op :maxima) ;; yes, same as (9)

(14) (cl-user::run) ;; should bring up Maxima banner & input prompt


> Furthermore can I emmbed maxima in a Java Programm with ABCL?

Yes. I've appended an example program. Command line to compile it:

  javac -cp /path/to/abcl.jar -d /path/to/compiled/class abcl_maxima.java

To execute it: (you must be in the Maxima src directory)

  java -cp /path/to/compiled/class:/path/to/abcl.jar abcl_maxima

I get: (takes a minute or two to load Maxima)

loading Maxima ... finished.
x.getClass => class org.armedbear.lisp.Cons
x = org.armedbear.lisp.Cons at 1748ba8
x.javaInstance => org.armedbear.lisp.Cons at 1748ba8
x.javaInstance.getClass => class org.armedbear.lisp.Cons
4 factors of 12341234
factor: 2, multiplicity: 1
factor: 73, multiplicity: 1
factor: 137, multiplicity: 1
factor: 617, multiplicity: 1


Note that all user functions have names which begin with dollar sign.
E.g. user function ifactors <==> $IFACTORS in Lisp

If you need help with Lisp programming for Maxima, ask questions on the
mailing list. See: http://maxima.sourceforge.net/maximalist.html

Hope this helps, have fun, & good luck.

Robert Dodier

PS. Example program abcl_maxima.java:

// abcl_maxima.java -- example program for calling Maxima from Java via ABCL
// copyright 2012 by Robert Dodier
// I release this work under terms of the GNU General Public License

import org.armedbear.lisp.Interpreter;
import org.armedbear.lisp.Package;
import org.armedbear.lisp.Packages;
import org.armedbear.lisp.Symbol;
import org.armedbear.lisp.Function;
import org.armedbear.lisp.LispObject;
import org.armedbear.lisp.Fixnum;
import org.armedbear.lisp.Bignum;
import org.armedbear.lisp.Cons;

public class abcl_maxima
{
	public static void main (String [] args) throws Exception
	{
		int a;

		if (args.length > 0)
			a = Integer.parseInt (args [0]);
		else
			a = 12341234;

		Interpreter I = Interpreter.createInstance ();
		System.out.print ("loading Maxima ... ");
		I.eval ("(require 'asdf)");
		I.eval ("(asdf:operate 'asdf:load-op :maxima)");
		System.out.println ("finished.");
		Package P = Packages.findPackage ("MAXIMA");

	//	java.util.List <Symbol> L = P.getAccessibleSymbols ();
	//	for (Symbol S : L)
	//	{
	//		if (P.equals (S.getPackage ()))
	//			System.out.println (S.toString ());
	//	}

		Symbol S = P.findAccessibleSymbol ("$IFACTORS");
		Function F = (Function) S.getSymbolFunction ();
		LispObject x = Bignum.getInstance (a);
		x = F.execute (x);
		System.out.println ("x.getClass => " + x.getClass ());
		System.out.println ("x = " + x);
		System.out.println ("x.javaInstance => " + x.javaInstance ());
		System.out.println ("x.javaInstance.getClass => " + x.javaInstance () . getClass ());

		int n = ((Cons) x).length ();
		System.out.println ((n - 1) + " factors of " + a);

		for (int i = 1; i < n; i++)
		{
			Cons x1 = (Cons) ((Cons) x).NTH (i);
			Fixnum f = (Fixnum) x1.NTH (1);
			Fixnum m = (Fixnum) x1.NTH (2);
			System.out.println ("factor: " + f.intValue () + ", multiplicity: " + m.intValue ());
		}
	}
}





More information about the armedbear-devel mailing list