I am trying to do something which I am almost able to do but I have what seems like a final roadblock.
My goal is to be able to call procedures that dynamically update the maple initialization file (init on a Mac, located at ~/Library/Frameworks/Maple.framework/Versions/2022/lib/init).
Let's say this file starts empty.
I want to be able to use a procedure addPackageDirectoryToLibname that will remove all the contents of init and replace it with a newly constructed string.
The newly constructed string will be libname: and then the previous libname string (which is just libname while the procedure is executing), prepended with an argument to the procedure, packageDir.
So, something like libname := MyNewDir, libname:
I also want to have a procedure removeEntryFromLibname that removes the entry in libname at the argument index.
Now I can already do all of this EXCEPT I can't remove the contents of the file init. Therefore, I am simply adding ever longer strings to init. I don't want to delete the file and recreate it, though I could do this. How do I wipe the contents of init clean programatically?
A few observations
- I had a working version of addPackageDirectoryToLibname but I realized that it was too limited (for the record, it was just adding a new line to the init file each time. The new line was something like libname := MyNewDirectory, libname:.
- There is a problem that for my personal use is minor (but if this were for more widespread use I would want to fix it): if addPackageDirectoryToLibname works, you can't call it twice in a row without a restart:, because it depends on the current value of libname. After adding something to libname if you add something else, this something else will be added to the old libname, not the libname that was updated.
If you'd like to see the code I have so far, you can see it in this Github repository.