tags:

views:

84

answers:

5

I tried the following:

$ cat args.sh
\#! /Applications/ccl/dx86cl64
(format t "~&~S~&" *args*)

$ ./args.sh 

Couldn't load lisp heap image from ./args.sh

I can run lisp fine directly:

$ /Applications/ccl/dx86cl64
Welcome to Clozure Common Lisp Version 1.5-r13651  (DarwinX8664)!

? 

Is it possible to write a shell script to run lisp code with Clozure CL? I am sure I am doing something silly.

I installed it from: http://openmcl.clozure.com/

Thanks

A: 

You have to make sure, that the kernel can load a Lisp memory image. The default behaviour is for the kernel to look for a file, which is named like the kernel binary with ".image" appended, i.e., if you start CCL using dx86cl64, then the image loaded is dx86cl64.image from the same directory. You can modify this behaviour by supplying the image explictely using the --image option. Try dx86cl64 --help for more information.

Dirk
+1  A: 
Charlie Martin
Thanks for the suggestion. I tried this:#! /bin/bashexec /Applications/ccl/dx86cl64 --eval '(format t "hello script")'That works, except that I get the lisp prompt after the method executes. How can I exit out of the loop?$ ./args.sh hello scriptWelcome to Clozure Common Lisp Version 1.5-r13651 (DarwinX8664)!?
M-Y
(bye) I believe.
Charlie Martin
At least up until Clozure 1.4 `(bye)` isn't available. `(ccl::quit)`, however, is (thus `(quit)` will also work if you're on the `ccl` package).
Edgar
I use about 6 variants of lisp and these sorts of things are maddeningly hard to keep straight. Thanks.
Charlie Martin
A: 

See the scripts subdirectory of your ccl directory. It should have some scripts you can adapt and use.

Rainer Joswig
I did. Unfortunately they are not lisp code scripts, but shell utilities.
M-Y
A: 

You cannot call the script like this from the command line:

/Applications/ccl/dx86cl64 myscript

can you?

I think that you need to call it like this (I don't have Clozure CL here, so I can't test):

/Applications/ccl/dx86cl64 -b -l myscript

So, your script should start like this:

#!/Applications/ccl/dx86cl64 -b -l
...
Svante
+1  A: 

Just following up on Charlie Martin's answer and on your subsequent question. The dx86cl64 --eval <code> will fire up a REPL, so if you want to fire up a given script then quit, just add this to the end of your script: (ccl::quit). In the example you provided, this would do the trick:

#! /bin/bash 
exec /Applications/ccl/dx86cl64 --eval '(progn (format t "hello script") (ccl::quit))'

A nicer script would be the following:

#! /bin/bash
exec /Applications/ccl/dx86cl64 -b -e '(progn (load "'$1'") (ccl::quit))'

Put that into a file, load-ccl-script.sh (or other name of your choice). Then the following interaction works:

$ echo '(format t "weeee!")' > a.lisp
$ sh load-ccl-script.sh a.lisp
weeee!
$ _
Edgar
Thanks! (I guess the 'sh' is redundant in 'sh load-ccl-script.sh a.lisp'...)
M-Y
True, but without it I'd had to include the `chmod +x load-ccl-script.sh` line - the 3 characters were a bit more concise, and since this wasn't the purpose of the snippet i went the lazy way :)
Edgar