title: Interact with a locally long-running Common Lisp image, possibly daemonized, from the command line
body: <p>How could one interact with a locally long-running Common Lisp image, possibly daemonized, from the command line?</p>
  
  <p>I know it is possible to <a href="https://stackoverflow.com/questions/20301668/running-a-common-lisp-function-from-a-terminal-command-prompt">run a Common Lisp function from a Terminal command prompt</a>, I am also aware of <a href="https://stackoverflow.com/questions/9796353/writing-common-lisp-code-that-executes-from-the-command-line-but-not-inside-the">this</a>.</p>
  
  <p>I would need to do a similar thing, but with a local, already <em>long-running</em> Common Lisp image, being able to poll available functions from the CLI or shell scripts.</p>
  
  <p>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?</p>
  
  <p>I though one could, for example, create a primitive web service, perhaps using <a href="https://github.com/fukamachi/woo" rel="nofollow noreferrer">woo</a> or <a href="https://github.com/edicl/hunchentoot" rel="nofollow noreferrer">Hunchentoot</a>, calling functions and fetching returned values via <code>curl</code> or <code>wget</code>, but it feels a little convoluted.</p>
  
  <p>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.</p>
  
  <p>Is there perhaps a way to reach a swank backend, outside of SLIME?</p>
  
  <p>If possible at all, what would be the lisp idiomatic way of doing that?</p>
  
  <p>I would be grateful for any pointers.</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <h3>Additional note</h3>
  
  <p>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: <a href="http://franz.com/support/tech_corner/telnetserver.lhtml" rel="nofollow noreferrer">telnet for remote access to a running application</a></p>
  
  <p>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.</p>
  
  <h3>Some additional pointers, and thanks</h3>
  
  <p>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.</p>
  
  <p>I was all ready to start writing a local server, perhaps using one of the fine Common Lisp libraries, like:</p>
  
  <ul>
  <li><a href="https://github.com/usocket/usocket" rel="nofollow noreferrer">usocket: Universal socket library for Common Lisp</a></li>
  <li><a href="https://github.com/sionescu/iolib" rel="nofollow noreferrer">iolib: Common Lisp I/O library</a> </li>
  <li><a href="https://github.com/orthecreedence/cl-async" rel="nofollow noreferrer">cl-aync: Asynchronous IO library for Common Lisp</a></li>
  </ul>
  
  <p>But, thanks to Stanislav Kondratyev, I didn't have to. He pointed out an already existing solution that nicely answer my question, <a href="https://github.com/rpav/ScriptL" rel="nofollow noreferrer">ScriptL: Shell scripting made Lisp-like</a></p>
  
  <p>I tested it with success on Linux, FreeBSD and OS X, just make sure to install the <a href="https://github.com/sionescu/libfixposix" rel="nofollow noreferrer">thin wrapper over POSIX syscalls</a> 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 <code>netcat</code>. </p>