-   Programming (
-   -   running LISP interpreter as background process (

prokhor 08-11-2009 05:39 PM

running LISP interpreter as background process
Hi there

I try to run some lisp interpreter as a background process communicating with other applications by reading and writing from files.
The intention is as follows:

- I start the lisp interpreter as a backgroud process
- a file with initial commands (initfile) is loaded
- the interpreter stays active, waiting for additional commands or an exit signal
- every time a new line is added to the initfile (or another specified file) the interpreter reads this line, evaluates it and writes the output to another file
- the interpreter stops when receiving order to do so....

My problem is:

every time the interpreter reaches the initfile's EOF it exits, so I have to reload the whole thing with every new line

I tried:

- clisp <infile >outfile &
- nohup 0<&- 1<infile >outfile &
- nohup 0<&- >/dev/null #no way to communicate

All without success

I hope you can help me, thx

Ps: I am working on a x86 32Bit with linux

ntubski 08-11-2009 07:24 PM

You could use a fifo:

mkfifo repl-pipe.fifo

clisp < repl-pipe.fifo > output &

tail -f input > repl-pipe.fifo &

wait $LISP_PID
kill $TAIL_PID
rm repl-pipe.fifo

But it might be better to write a lisp program to listen on a socket.

bigearsbilly 08-12-2009 03:38 PM

if you have an init file for clisp


clisp -i init.lisp

it won't exit then.
and it will be in normal interactive mode.

You cannot monitor a file in the way you suggest.
when you open a file it's read there and then and closed, any
subsequent changes will not work.
A fifo won't do what you want either.

what are you trying to do?

(It's good to see someone using lisp though.)

sockets are easy if you want them...

bigearsbilly 08-12-2009 04:06 PM

Here is a simple socket server...


(defconstant +portnum+ 50123)
(with-open-stream (socket (socket-accept (socket-server +portnum+)))

    (format t "~&Got a punter..~%")

        (eval (read socket)))


run it like so:

clisp -i your-init-file socket.lisp

to illustrate it
you can interact in another xterm using netcat

nc localhost 50123

prokhor 08-20-2009 04:30 PM


Originally Posted by bigearsbilly (Post 3640907)
if you have an init file for clisp

what are you trying to do?

(It's good to see someone using lisp though.)


First of all my excuse for the late answer...

I have a program with an output like this:
(class living_thing
(spec human
(prop has_legs))
(spec bird (prop has_wings))))

The program spits that kind of code out whenever it has computed its own input.
Now I have three problems:

1. How do I feed my program time after time (solved by FIFO)
2. How do i lookup the data:
here the problems are:
1. I dont know the structures depht (which is variable) 2. I dont know how to retrieve the information once stored because of 1.
3. How to store it in a DB (solved conceptually by my own)

Any ideas?

bigearsbilly 08-21-2009 06:47 AM

what sort of data structure?
is it a hash-table?

now you wondered why lisp has read macros and prin1
did you know that you can prin1 a lisp data structure out to a file
(a list, a hash table etc.)
then read it back in again as is!

All times are GMT -5. The time now is 01:37 AM.