Use running lisp as script interpreter

Discussion of Common Lisp
Post Reply
beren
Posts: 11
Joined: Thu Mar 05, 2009 4:08 pm

Use running lisp as script interpreter

Post by beren » Sat Sep 11, 2010 5:04 am

As I use stumpwm (a common-lisp window manager), I normally always have a lisp process running. So I was wandering if there is a way I can use that instance to evaluate "scripts"?

What I want to do is to write small lisp scripts and instead of executing them in their own separate instaces, I want to send them to an already running SBCL.
For example, I could try connecting via swank, but I don't know how to stablish a connection without slime.
Is there some way to do this?

Thanks!

Duke
Posts: 38
Joined: Sat Oct 17, 2009 10:40 pm
Contact:

Re: Use running lisp as script interpreter

Post by Duke » Sat Sep 11, 2010 5:36 am

beren wrote:As I use stumpwm (a common-lisp window manager), I normally always have a lisp process running. So I was wandering if there is a way I can use that instance to evaluate "scripts"?

What I want to do is to write small lisp scripts and instead of executing them in their own separate instaces, I want to send them to an already running SBCL.
If I'm understanding correctly, you should try it this way...

In your .stumpwmrc:

Code: Select all

(load "/path/to/my/script.lisp") 
In script.lisp:

Code: Select all

(defun my-scripty-func ()
  ...)
...And then use Stump's "colon" command to eval my-scripty-func. Or if colon is too clunky (which it is, IMO) do something like this:

Code: Select all

(defcommand do-scripty-thing () () (my-scripty-func))
(define-key *root-map* (kbd "C-M-Z") "do-scripty-thing")
"If you want to improve, be content to be thought foolish and stupid." -Epictetus

beren
Posts: 11
Joined: Thu Mar 05, 2009 4:08 pm

Re: Use running lisp as script interpreter

Post by beren » Sat Sep 11, 2010 6:04 am

Thanks Duke,
Although something like that would work, I was thinking in something more generic. Just executing my lisp scripts in a terminal as ./script.lisp.
where script.lisp would be something like

Code: Select all

#!/usr/bin/env lispconnect
(defun ...()...)
and lispconnect would be in charge of connecting to a running lisp or spawning a new one, and send the rest of the script. That way there is no need to start a new process each time, and the state of the machine is persistent.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Use running lisp as script interpreter

Post by gugamilare » Sat Sep 11, 2010 6:18 am

I would create a thread in your "server" that is responsible for listening to a socket. Whenever something is received from that socket, it interprets that as a string that contains code. Then I would write a small C or Lisp program that sent this code through that socket.

One nice alternative would be to use DBus to send messages. There is an attempt of a DBus client here, unfortunately I think it can't even send or receive complete messages yet.

beren
Posts: 11
Joined: Thu Mar 05, 2009 4:08 pm

Re: Use running lisp as script interpreter

Post by beren » Sat Sep 11, 2010 10:26 am

I think sockets are a good alternative. Althought they seem quite implementation dependent.
I'll try to code something simple, and if I succed I'll post it here. Of course if anyone else already have something like this feel free to post :D

Post Reply