How might you call a Lisp program from a Rails application?... For example, allow the end user to enter a block of text in the Rails web app, have the text processed by the Lisp program and return results to the Rails app?
+7
A:
There are a couple ways that come to mind:
- Use Ruby's ability to execute command-line utilities. Communicate with the Lisp program via standard in, and have the Lisp program output its result over stdout.
- Do the same thing as above, but communicate via named pipes instead. Have your Ruby code write data into a named pipe, then have the Lisp program read from that pipe, and write data out over another named pipe which you then read with your Ruby app. The Lisp program can either run in the background as a daemon that checks for data on its incoming pipe, or you can fire it up as-needed using Ruby's command-line utilities (as above).
- Find a Ruby-Lisp bridge. I have no experience with such a bridge (nor do I know off-hand if one even exists) and I think the above 2 mechanisms are easier, but your mileage may vary.
mipadi
2009-10-29 16:48:52
+6
A:
Another simple way is to have Lisp running a HTTP server and contact Lisp from the outside via HTTP requests.
Rainer Joswig
2009-10-29 16:59:26
I'm not sure that most people would consider that as simple as above, but perhaps for RoR people it might even be simpler...
Brian Knoblauch
2009-10-29 17:06:38
In a web setting this is the usual service-oriented architecture. There are lots of web servers for Lisp and exchanging data via HTTP requests is easy. All you need to do is let the Lisp server respond to a POST request.
Rainer Joswig
2009-10-29 19:46:28
+2
A:
It would depend on how often it's going to happen.
- If it's once in a blue moon, then just run a backquote command that starts the lisp interpreter, or popen it and write to it.
- If it happens all the time, you will need to have Lisp already running, so the question then is how to communicate. Any of the interprocessor mechanisms will work, but I would suggest a TCP socket for development, testing, and production flexibility.
- If it happens a million times a day, but a toy Lisp would be good enough, it is a simple matter to implement Lisp with Ruby classes. This was done as chapter 8 of Practical Ruby Projects.
DigitalRoss
2009-10-29 17:08:02
+3
A:
CL-JSON supports JSON-RPC. It's very easy to set up with a web server such as Hunchentoot to have a Lisp-based web service that anything that speaks JSON-RPC (e.g. this) can use.
jlf
2009-10-29 18:44:25