Maxima and Ruby Integration


#1

I’m looking to write a javascript heavy clientside program with a
something serverside backend that connects to the free maxima math
program. I have extensive knowledge of ruby on rails, so I would prefer
to call Maxima with ruby, but I don’t know if this is even possible. Its
fairly easy to call Maxima (with a lisp implementation) using ANSI C, it
is a little less easy to implement using JAVA with a lisp implementation
like Armed Bear, but I don’t see any information about using Maxima with
Ruby or Ruby on Rails.

Since Maxima as far as I can tell is the number one most powerful
open-source math program, and RoR is my favorite open-source web
framework, it would seem like a good fit. Has anyone implemented any
math heavy applications with RoR, and can you give me any advice (anyone
know if RoR and maxima is possible) ??


#2

Well since it probably supports command line arguments, you could
always use ‘system’ method

On Jan 31, 5:22 am, Richard S. <rails-mailing-l…@andreas-


#3

I Read up on some of my options, found that I can run maxima as a
subprocess using:

IO.popen(“maxima”)

but how do I pass in arguments and get a response? After i start
“maxima” i should be able to run “1 + 1;” and return the answer of “2”?

Also, Is popen the best way to go about running this process?


#4

I tried the following but i’m getting errors…am I missing something
here?

f = IO.popen(“maxima”)
=> #IO:0x208d5e8

f.puts “1+1;”
IOError: not opened for writing
from (irb):7:in write' from (irb):7:inputs’
from (irb):7

f.close_write
IOError: closing non-duplex IO for writing
from (irb):8:in `close_write’
from (irb):8


#5

Pass “w” as second argument: IO.popen(“maxima”, “w”)

On Feb 1, 8:52 am, Richard S. <rails-mailing-l…@andreas-


#6

Thanks that did the trick. Do you know if there is an easy way to get
the last result, or everything without having to do so many “gets”? I
tried .each and readlines but with not much success. Or at least a way
to determine when the last line has been "get"en without error-ing out?

max = IO.popen(“maxima”, “w+”)
=> #IO:0x201bccc

max.puts “1+1;”
=> nil

max.gets
=> “Maxima 5.15.0 http://maxima.sourceforge.net\n”

max.gets
=> “Using Lisp SBCL 1.0.17\n”

max.gets
=> “Distributed under the GNU Public License. See the file COPYING.\n”

max.gets
=> “Dedicated to the memory of William Schelter.\n”

max.gets
=> “The function bug_report() provides bug reporting information.\n”

max.gets
=> “(%i1) \n”

max.gets
=> “(%o1) 2\n”

max.puts “1+9;”
=> nil

max.gets
=> “(%i2) \n”

max.gets
=> “(%o2) 10\n”

max.gets


#7

What about readlines.last?

On Feb 1, 7:40 pm, Richard S. <rails-mailing-l…@andreas-


#8

Hm I’m not sure why does it freeze. You could try max.to_a.last or if
all else fails try just skipping unnecessary lines using while loop

On Feb 3, 3:36 pm, Richard S. <rails-mailing-l…@andreas-


#9

Thanks for the help, but alas calling max.to_a results in an
unrecoverable error as well.

I will have to just skip unnecessary lines…


#10

max = IO.popen(“maxima”, “w+”)
=> #IO:0x2535b68

max.readlines.last
^CIRB::Abort: abort then interrupt!!
from /opt/local/lib/ruby/1.8/irb.rb:81:in irb_abort' from /opt/local/lib/ruby/1.8/irb.rb:243:insignal_handle’
from /opt/local/lib/ruby/1.8/irb.rb:66:in start' from (irb):2:incall’
from (irb):2:in `readlines’
from (irb):2

When you run max.readlines.anything script/console freezes