[Maxima] "load" with guards etc. ??
robert.dodier at gmail.com
Mon Jan 7 21:27:55 CST 2008
On 12/21/07, Oliver Kullmann <O.Kullmann at swansea.ac.uk> wrote:
> So "load" is the equivalent of "#include" in the C/C++ world.
> However, apparently there is no functionality concerned with
> preventing multiple inclusions (especially circular inclusions)?
> I wonder how other users deal with that problem --- everybody writes
> his little utilities to handle this, I guess? Or are some underlying
> clisp-mechanisms used?
I've tinkered with a namespace mechanism for Maxima which is
based on the Lisp package system. The current version of it is in cvs.
I am hoping this could be useful for encapsulating add-on programs.
Here is an example session.
(%i1) load (namespaces)$
(%i2) in_namespace ();
(%o2) #<MAXIMA package>
(%i3) in_namespace (Foo);
(%o3) #<$Foo package>
($%i4) aa : 1234;
($%i5) f (x) := aa - x;
(%o5) f(x) := aa - x
($%i6) export (f);
($%i7) in_namespace (maxima);
(%o7) #<MAXIMA package>
(%i10) symbols (Foo);
(%o10) [Foo|, Foo|%i3, Foo|%i4, Foo|%i5, Foo|%i6, Foo|%i7,
Foo|%o3, Foo|%o4, Foo|%o5, Foo|%o6, Foo|aa, Foo|f, Foo|x]
(%i11) external_symbols (Foo);
(%i12) aa : 9876;
(%o14) [Foo|aa, aa]
(%i15) f (1);
(%i16) import (Foo);
(%i17) f (1);
There are some rough edges but I think it is not too far from workable.
In particular the stuff about exporting symbols from the :maxima
package is probably confused; either too many symbols or too few,
I'm not sure which. Someone who understands the Lisp package
system better than me is invited to make suggestions about that
or anything else.
Specifically about loading something just once, there is
load_namespace(foo) which calls load(foo) only if there is not
already a namespace named foo. Dunno if it handles circular
Comments in namespaces.lisp provide more info and examples,
and there is a test script rtest_namespaces.mac as well.
More information about the Maxima