maxima_calculus.load("blah.mac") throws, load("blah.mac'") in sage --maxima works

63 views
Skip to first unread message

Dima Pasechnik

unread,
Jan 12, 2017, 3:42:28 PM1/12/17
to sage-devel
I am trying to understand how to load Maxima user code into maxima_calculus().

Running 
maxima_calculus.load("blah.mac") throws a TypeError:
ECL says: THROW: The catch MACSYMA-QUIT is undefined.

maxima.load("blah.mac") just hangs indefinitely.

Trying the same code in sage --maxima, there
load("blah.mac'"); works 
It does emit quite a few messages from the ECL
lisp compiler though, saying ";;; Compiling...", ";;; Emitting code", etc.

What am I doing wrong?
Do I miss some kind of building step?





Nils Bruin

unread,
Jan 12, 2017, 4:14:22 PM1/12/17
to sage-devel
This works:

sage: maxima_calculus.load('to_poly_solve')
\"/usr/local/sage/sage-git/local/share/maxima/5.35.1/share/to_poly_solve/to_poly_solve.mac\"

whereas this does not:

sage: maxima_calculus.load('to_poly_solve.mac')
TypeError: ECL says: In function PATHNAME, the value of the only argument is
  ((MNCTIMES SIMP) $TO_POLY_SOLVE $MAC)
which is not of the expected type (OR FILE-STREAM STRING PATHNAME)

(clearly, the filename is parsed rather than taken as a string)

This does seem to work:

sage: maxima_calculus.load('"to_poly_solve.mac"')
\"/usr/local/sage/sage-git/local/share/maxima/5.35.1/share/to_poly_solve/to_poly_solve.mac\"

as does this:

sage: maxima_calculus.load('"/usr/local/sage/sage-git/local/share/maxima/5.35.1/share/to_poly_solve/to_poly_solve.mac"')
\"/usr/local/sage/sage-git/local/share/maxima/5.35.1/share/to_poly_solve/to_poly_solve.mac\"

so it looks like there's nothing particularly wrong with the load command once you let it deal with strings properly.

If you want to take it a little closer to the metal you can do

sage: maxima_calculus._eval_line('load("to_poly_solve.mac")')
'\\"/usr/local/sage/sage-git/local/share/maxima/5.35.1/share/to_poly_solve/to_poly_solve.mac\\"

which seems to work as well.

Working with a nonexisting file gives a rather uninformative error message:

sage: maxima_calculus.load('"blah.mac"')
TypeError: ECL says: Error executing code in Maxima:

whereas maxima tells exactly what goes wrong. So the error message capturing technology can perhaps be improved.

Robert Dodier

unread,
Jan 12, 2017, 10:35:03 PM1/12/17
to sage-...@googlegroups.com
On 2017-01-12, Dima Pasechnik <dim...@gmail.com> wrote:

> maxima_calculus.load("blah.mac") throws a TypeError:
> ECL says: THROW: The catch MACSYMA-QUIT is undefined.

Well, there is more than one way to process an input file in Maxima, and
in one of those ways, the function reading the file throws MACSYMA-QUIT
and the caller is supposed to catch that to know the end of file was
reached. So it sounds as if the file was opened and the content was read
but the end of file wasn't handled correctly. Is there a way to see if
anything was actually processed? e.g. maybe look at values or function
definitions or print output.

> maxima.load("blah.mac") just hangs indefinitely.

A wild guess. Is it possible that it didn't switch back to reading from
the console after the file was processed? Completely guessing here.

best,

Robert Dodier

Nils Bruin

unread,
Jan 13, 2017, 3:15:53 AM1/13/17
to sage-devel
On Thursday, January 12, 2017 at 7:35:03 PM UTC-8, Robert Dodier wrote:
On 2017-01-12, Dima Pasechnik <dim...@gmail.com> wrote:

> maxima_calculus.load("blah.mac") throws a TypeError:
> ECL says: THROW: The catch MACSYMA-QUIT is undefined.

I think the problem here is that

maxima_calculus.load("/path/name/thats/not/valid/maxima/syntax")

gets translated to executing in maxima:

load(/path/name/thats/not/valid/maxima/syntax)

so a parsing error occurs, which doesn't get caught properly.

Dima Pasechnik

unread,
Jan 13, 2017, 2:01:15 PM1/13/17
to sage-devel
There is also a problem parsing ''' (thanks, google-groups, for editing it for us :-)) as ' " (or " ', depending on the context).
At least it did hit me...

By the way, is there a way to assign bindings like
maxima_calculus.sin() to Maxima functions from just loaded Maxima code on the fly, 
without going into trouble of installing a Maxima package, rebuilding Sage's Maxima, etc?

Nils Bruin

unread,
Jan 13, 2017, 6:38:59 PM1/13/17
to sage-devel
On Friday, January 13, 2017 at 11:01:15 AM UTC-8, Dima Pasechnik wrote:
There is also a problem parsing ''' (thanks, google-groups, for editing it for us :-)) as ' " (or " ', depending on the context).
At least it did hit me...

cut/paste works fine for me, so I think the only confusing thing is that google-groups uses a proportional font by default. It didn't change the actual characters.
 
By the way, is there a way to assign bindings like
maxima_calculus.sin() to Maxima functions from just loaded Maxima code on the fly, 
without going into trouble of installing a Maxima package, rebuilding Sage's Maxima, etc?

That just works, even for functions that don't exist (yet).

sage: import sage.interfaces.maxima_lib
sage: M=sage.interfaces.maxima_lib.maxima
sage: M.g(x)

see maxima_calculus.__getattr__ for how.

Reply all
Reply to author
Forward
0 new messages