Is there a way to force code to be run inside maxima block?

Viewed 74

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.

1 Answers

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.

Related