2

I am trying to evaluate some code inside a block in Maxima but it does not seem to be working. If I want have something of the form

block( load("my_file.mac"), do_stuff )

it does not seem to load the file. I wanted to circumvent this problem by defining the only thing I need from that file in the following way

block( "implies"(p, q) := not p or q, infix("implies"), expr: p implies q, do_other_stuff)

But again, I get an error that implies is not an infix operator. I think this is because both load and infix have a return value (done and implies respectively in my case) which somehow corrupts the block.

It is absolutely necessary that either the entire Maxima code is contained inside a block. So although both

load("my_file.mac"); block(do_stuff)

and

"implies"(p, q) := not p or q; infix("implies"); block(expr: p implies q, do_other_stuff)

work. This is not an option for me.

Misha
  • 21
  • 1

1 Answers1

1

All of a block is parsed before evaluating it. So if the block says something like

block (load ("my_file.mac"), p implies q);

then "implies" has to be defined before parsing the block -- it can't be defined within the block.

Note that operator definitions are global in Maxima. If you write block(infix("implies"), ...), then "implies" is still a global definition; it is not limited to the block in which it was defined.

Maybe you can say more about what you are trying to achieve.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Thanks! This already helps. What I am trying to do is interpret an expression which is given to me by openmath/mathML. More specifically: someone writes an expression online and this is automatically converted to a Maxima expression, in this specific case $p \Rightarrow q$ is interpreted as "p implies q". I want to write some code that can recognise is the correct expression has been given and some other code that can check if it is not the correct expression but, for example, with a $p$ or $q$ interchanged. – Misha May 11 '20 at 15:37
  • OK, sounds good. Have you heard of STACK? It is a system for automatically evaluating answers which is based on Maxima. Maybe you can make use of that in some way. If you are parsing input strings, maybe `parse_string` is relevant. About checking results, you might consider using pattern matching (defrule, defmatch, and matchdeclare). Note that "pattern matching" in Maxima means matching expressions, not strings. – Robert Dodier May 11 '20 at 16:04