Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Clozure CL (Lisp) from a shell script on OS X?

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/

like image 579
M-V Avatar asked Aug 08 '10 15:08

M-V


2 Answers

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!
$ _
like image 59
Edgar Gonçalves Avatar answered Oct 21 '22 17:10

Edgar Gonçalves


The issue is in your shebang line:

\#! /Applications/ccl/dx86cl64

In a UNIX file, the first 16 bits is called the "magic number". It happens that the magic number for an executable script is the same bit configuration as the characters "#!". The first 16 bits of your file have the same configuration as "\#", and UNIX won't buy that.

It is possible to add magic numbers, but it isn't easy or portable, so what you need is a way to invoke the script. I'd suggest

#! /bin/bash
exec /Applications/ccl/dx86cl64 

with appropriate arguments etc for your script. (The exec builtin causes the current process to be loaded with the named executable without forking, so you don't have a spare process lying about.)

Update

In your particular case, you'll want something like

@! /bin/bash
exec /Applications/ccl/dx86cl64 --eval '(format t "~&~S~&" *args*)'

See the command line args for Clozure for why.

like image 39
Charlie Martin Avatar answered Oct 21 '22 17:10

Charlie Martin