Defining file_type extensions



On 2/12/11 6:25 PM, David Billinghurst wrote:
> On 13/02/2011 5:55 AM, Rupert Swarbrick wrote:
>> ObsessiveMathsFreak<obsessivemathsfreak at obsessivemathsfreak.org>
>> writes:
>>> Hello,
>>>
>>> I've encountered a problem in the latest versions of
>>> maxima. Specially, the load function no longer works on my code
>>> because I have given the .mxs extension to all my code files. So now I
>>> have
>>>
>>> (%i3) load("weightingmatrix.mxs");
>>> Load failed for weightingmatrix.mxs
>>>   -- an error. To debug this try: debugmode(true);
>>>
>>> Simply renaming individual files solves this issue
>>>
>>> (%i4) load("weightingmatrix.mac");
>>> 0 errors, 0 warnings
>>> (%o4)                         weightingmatrix.mac
>>>
>>> But I have many dozens of mxs files which all contain mxs calls in
>>> their code. Rather than re-write everything, I would like to define
>>> mxs as a maxima file type so that file_type recognises it as maxima
>>> code.
>> The problem comes from the fact that load() can either load in lisp code
>> or Maxima code. To decide which it's getting, it seems to check for the
>> file extension, defaulting to lisp. So the errors you get come from it
>> trying to read weightingmatrix.mxs as lisp, which it isn't!
>>
>> A solution/workaround is to use batchload() instead, which seems to work
>> the same, but assume that you're giving it Maxima code.
>>
>> Rupert
>
> The file suffixes used by load are hard coded in function $file_type
> in mload.lisp.
>
>    (defun $file_type (fil)
>       (let ((typ ($pathname_type fil)))
>         (cond
>           ((member typ '("l" "lsp" "lisp") :test #'string=)
>            '$lisp)
>           ((member typ '("mac" "mc" "demo" "dem" "dm1" "dm2" "dm3" "dmt")
>                :test #'string=)
>            '$maxima)
>           (t
>            '$object))))
>
> You could put a modified version of this function in your
> maxima-init.lisp file - see
> http://maxima.sourceforge.net/ui-tips.html
This has come up several times now.  Perhaps it's time to allow the user
to change this easily. 

I propose adding two new variables $file_type_lisp and
$file_type_maxima, defaulting to the values above.  Then the user can
change them however they want.

(Of course, you solution works nicely too.)

Ray