Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended way to make & load a library?

Tags:

maxima

I want to make a small "library" to be used by my future maxima scripts, but I am not quite sure on how to proceed (I use wxMaxima). Maxima's documentation covers the save(), load() and loadFile() functions, yet does not provide examples. Therefore, I am not sure whether I am using the proper/best way or not. My current solution, which is based on this post, stores my library in the *.lisp format.

As a simple example, let's say that my library defines the cosSin(x) function. I open a new session and define this function as

(%i0) cosSin(x) := cos(x) * sin(x);

I then save it to a lisp file located in the /tmp/ directory.

(%i1) save("/tmp/lib.lisp");

I then open a new instance of maxima and load the library

(%i0) loadfile("/tmp/lib.lisp");

The cosSin(x) is now defined and can be called

(%i1) cosSin(%pi/4)

(%o1) 1/2

However, I noticed that a substantial number of the libraries shipped with maxima are of *.mac format: the /usr/share/maxima/5.37.2/share/ directory contains 428 *.mac files and 516 *.lisp files. Is it a better format? How would I generate such files?

More generally, what are the different ways a library can be saved and loaded? What is the recommended approach?

like image 944
Gael Lorieul Avatar asked Feb 02 '17 12:02

Gael Lorieul


1 Answers

Usually people put the functions they need in a file name something.mac and then load("something.mac"); loads the functions into Maxima.

A file can contain any number of functions. A file can load other files, so if you have somethingA.mac and somethingB.mac, then you can have another file that just says load("somethingA.mac"); load("somethingB.mac");.

One can also create Lisp files and load them too, but it is not required to write functions in Lisp.

Unless you are specifically interested in writing Lisp functions, my advice is to write your functions in the Maxima language and put them in a file, using an ordinary text editor. Also, I recommend that you don't use save to save the functions to a file as Lisp code; just type the functions into a file, as Maxima code, with a plain text editor.

Take a look at the files in share to get a feeling for how other people have gone about it. I am looking right now at share/contrib/ggf.mac and I see it has a lengthy comment header describing its purpose -- such comments are always a good idea.

like image 198
Robert Dodier Avatar answered Dec 19 '22 08:12

Robert Dodier