Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interact with a locally long-running Common Lisp image, possibly daemonized, from the command line

How could one interact with a locally long-running Common Lisp image, possibly daemonized, from the command line?

I know it is possible to run a Common Lisp function from a Terminal command prompt, I am also aware of this.

I would need to do a similar thing, but with a local, already long-running Common Lisp image, being able to poll available functions from the CLI or shell scripts.

Is there a way to do that from a CLI, for example calling a function from a bash script, and receiving back whatever the function returns?

I though one could, for example, create a primitive web service, perhaps using woo or Hunchentoot, calling functions and fetching returned values via curl or wget, but it feels a little convoluted.

Of course, that is one of the many features of Emacs' SLIME, but I would need to call functions just from the CLI, without invoking Emacs.

Is there perhaps a way to reach a swank backend, outside of SLIME?

If possible at all, what would be the lisp idiomatic way of doing that?

I would be grateful for any pointers.


Update

Additional note

Many years ago, I was intrigued by being able to telnet into a long-running LISP image (I believe in this case uppercasing the name should be fine). If I remember correctly, it was available at prompt.franz.com. An article, somehow connected: telnet for remote access to a running application

Telnet is of course quite unsafe, but the usefulness of being able to access the Lisp application(s) in that way, for whatever reason, cannot be overstated, at least to some people.

Some additional pointers, and thanks

I would like to thank Basile Starynkevitch for his elaborate and thorough answer, especially on the theoretical aspect. I was looking for a more practical direction, specially connected to Common Lisp. Still, his answer is very instructive.

I was all ready to start writing a local server, perhaps using one of the fine Common Lisp libraries, like:

  • usocket: Universal socket library for Common Lisp
  • iolib: Common Lisp I/O library
  • cl-aync: Asynchronous IO library for Common Lisp

But, thanks to Stanislav Kondratyev, I didn't have to. He pointed out an already existing solution that nicely answer my question, ScriptL: Shell scripting made Lisp-like

I tested it with success on Linux, FreeBSD and OS X, just make sure to install the thin wrapper over POSIX syscalls first. Among many features (see README), it allows exposition of just selected functions, security is properly handled, and it even supply a custom C client, which builds as part of the ASDF load operation, and supports a number of new features, such as I/O, in place of netcat.

like image 874
gsl Avatar asked Jul 13 '15 06:07

gsl


People also ask

How do I run a Lisp program in command prompt?

Step 1: After logging into a CUIT machine, enter "lisp" after the $ shell prompt and then hit <return>. Another way is to run lisp via emacs: Meta-x run-lisp (i.e. hit 'esc' followed by 'x', type "run-lisp" and you'll be in lisp mode from which you can load files of lisp code...)

How do I run a Lisp program in Ubuntu?

With CLISP under a unix (like Ubuntu) you can simply add a shebang to the top of your file #!/path/to/clisp and in Ubuntu that would be #!/usr/bin/clisp and it will execute the code as a script. You need the file to contain proper Common Lisp file like: #!/usr/bin/clisp (princ "Hello, world!")


1 Answers

You may find scriptl useful: http://quickdocs.org/scriptl/. However, it depends on iolib, which depends on some nonstandard C or C++ library, so building it is not quite straighforward.

It is indeed possible to communicate with a swank server if you familiarize yourself with the swank protocol, which seems to be underdocumented (see e. g. here: https://github.com/astine/swank-client/blob/master/swank-description.markdown). However, this exposes a TCP socket over a network, which could be unsafe. Once I tried that, too, but I was not satisfied with the IPC speed.

A while ago I wrote a rather naive SBCL-specific server that uses a local domain socket for communication, and a client in C. It's very raw, but you could take a look: https://github.com/quasus/lispserver. In particular, it supports interactive IO and exit codes. The server and the client form the core of a simple framework for deploying Unix style software. Feel free to borrow code and/or contact me for explanations, suggestions, etc.

like image 143
Stanislav Kondratyev Avatar answered Sep 27 '22 16:09

Stanislav Kondratyev