path



Rupert Swarbrick <rswarbrick at gmail.com> writes:

>> I want to save the output ( graphic) file in the same directory as
>> batch file.
>> For example :
>>
>>  draw2d(file_name = concat(path,name),
>>
>> Now Maxima saves it to my home directory ( linux).
>> I can write path by hand, but maybe there is a clever method.

How about the following:

:lisp (defun $directory_part (pathname) ($printf nil "/~a" (apply #'combine-path (rest (pathname-directory pathname)))))

Now, in your batch file you can access the directory name via:

dirname : directory_part(load_pathname);

**if** you batchload (not load or batch) your Maxima script.

>
> Ok, but this seems really weird to me. I mean, I tend to save all the
> Maxima scripts that I write in a directory called ~/scripts/maxima. If
> they generate output, there's no reason that I'd want it generated in
> that directory!
>
> Maxima is probably saving things in the current directory, which I
> expect will default to the home directory if you run it from a shortcut
> in a GUI (eg desktop icon etc.)

Maxima does not save things in the cwd in general, rather maxima_tempdir
controls where most things get saved. There is a kludge which sets this
to $HOME at startup if the environment variable MAXIMA_TEMPDIR is unset.

You can set maxima_tempdir in Maxima (e.g. in maxima-init.mac), or use
the environment variable, to put stuff in /tmp, for example.

>
> Looking quickly through the manual, I couldn't see a way to change the
> current working directory in the Maxima language. Is that something you
> would use?

There aren't any directory/file stuff exposed to the Maxima top-level,
that I am aware of, but here are a few functions that let you do this:

We need to create a cd function without the system command, because
system launches a subshell, and we want to change the cwd of the Maxima process:

(%i1) :lisp (defun $cd (p) (xchdir p))
$CD

ssystem is a wrapper around system to make its output be returned as a
string. I do not understand why system doesn't do this...

(%i1) :lisp (defun $ssystem (cmd) (let ((s (make-string-output-stream))) (let ((*socket-connection* s)) ($system cmd)) (get-output-stream-string s)))
$SSYSTEM

(%i1) pwd() := ssystem("pwd");
(%o1)                       pwd() := ssystem("pwd")


>
>>>It seems load_pathname is working as documented:
>> ....
>> and : "batch has no return value.  "
>> You are right.
>> What is the reason for this behaviour ?
>
> The batch() function goes through a file and executes each statement in
> it. I don't think it was designed with "Call this file as a function" in
> mind, which is presumably how you're thinking about it. As such, the
> batch() function doesn't return anything relating to the computation
> that was performed.
>
> If you're trying to make "a function that runs and returns a value", I
> would suggest you use load() to load the definitions from some file,
> then call the function that has been loaded into the Maxima image.
>
> Rupert
>
> [1/2:application/pgp-signature Show Save:noname (315B)]
>
>
> [2:text/plain Hide]
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima

-- 
Leo Butler                <l_butler at users.sourceforge.net>
SDF Public Access UNIX System -   http://sdf.lonestar.org