Forum: Ruby on Rails Maxima and Ruby Integration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-01-31 04:22
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) ??
97f7778bd994b7e4c5ad025be0640bde?d=identicon&s=25 Andrius Chamentauskas (Guest)
on 2009-01-31 15:42
(Received via mailing list)
Well since it probably supports command line arguments, you could
always use 'system' method

On Jan 31, 5:22 am, Richard Schneeman <rails-mailing-l...@andreas-
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-01 04:09
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?
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-01 07:52
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:in `puts'
  from (irb):7
>> f.close_write
IOError: closing non-duplex IO for writing
  from (irb):8:in `close_write'
  from (irb):8
97f7778bd994b7e4c5ad025be0640bde?d=identicon&s=25 Andrius Chamentauskas (Guest)
on 2009-02-01 15:17
(Received via mailing list)
Pass "w" as second argument: IO.popen("maxima", "w")

On Feb 1, 8:52 am, Richard Schneeman <rails-mailing-l...@andreas-
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-01 18:40
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
97f7778bd994b7e4c5ad025be0640bde?d=identicon&s=25 Andrius Chamentauskas (Guest)
on 2009-02-03 12:27
(Received via mailing list)
What about readlines.last?

On Feb 1, 7:40 pm, Richard Schneeman <rails-mailing-l...@andreas-
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-03 14:36
>> 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:in `signal_handle'
  from /opt/local/lib/ruby/1.8/irb.rb:66:in `start'
  from (irb):2:in `call'
  from (irb):2:in `readlines'
  from (irb):2


When you run max.readlines.anything script/console freezes
97f7778bd994b7e4c5ad025be0640bde?d=identicon&s=25 Andrius Chamentauskas (Guest)
on 2009-02-03 15:36
(Received via mailing list)
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 Schneeman <rails-mailing-l...@andreas-
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-05 02:56
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...
This topic is locked and can not be replied to.