2

I often put the following lines at the beginning of my Maxima files

load("operatingsystem")$ 
chdir("/Users/tilda/Documents/progs/maxima/spm/")$

to make sure that output created by other programs from within Maxima is written into the current working directory as indicated above.

It does its job, yet this method is rather inflexible as the user's home directory, i.e.

/Users/tilda

is hardcoded into the program. So, when I exchange these files, users have to manually edit and adjust the code to their $HOME. To fix this I changed the code to various forms of

load("operatingsystem")$ 
chdir("$HOME/Documents/progs/maxima/spm/")$

just to get (Lisp) error messages. After consulting the manual and some trial and error I came up with this:

(%i1) load("operatingsystem")$
      getenv("HOME")$
      chdir(%)$
      chdir("Documents/progs/maxima/spm/")$
      getcurrentdirectory();

which works fine. For other users, i.e. matthias, the current directory now indeed is in their path.

(%o5) /Users/matthias/Documents/progs/maxima/spm/ 

However, I wonder if there is a more elegant and shorter way to achieve this.

Any suggestions appreciated.

Cheers Tilda

  • 1
    Looks like you have a working solution. I don't know if there is anything more elegant. Something to consider, you could add the path in question to `file_search_maxima` and/or `file_search_lisp` and omit the calls to `chdir`. – Robert Dodier Aug 12 '22 at 05:21
  • @RobertDodier Thanks for your fast reply and the suggestion to try `file_search_maxima` or `file_search_lisp` instead. But aren't these functions used for maxima- or lisp-files to be read in or written to disk? Where as my intention is to write, say output crated by **draw2d**, to a specified directory. So, I guess I'll have to stick to `chdir`. – tilda-a-steiner Aug 12 '22 at 06:31

0 Answers0