8

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/

5 Answers 5

6

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!
$ _
2
  • Thanks! (I guess the 'sh' is redundant in 'sh load-ccl-script.sh a.lisp'...)
    – M-V
    Aug 10, 2010 at 11:21
  • 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 :) Aug 10, 2010 at 17:09
2

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.

3
  • Thanks for the suggestion. I tried this: #! /bin/bash exec /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 script Welcome to Clozure Common Lisp Version 1.5-r13651 (DarwinX8664)! ?
    – M-V
    Aug 9, 2010 at 2:50
  • 1
    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). Aug 10, 2010 at 17:14
  • 1
    I use about 6 variants of lisp and these sorts of things are maddeningly hard to keep straight. Thanks. Aug 12, 2010 at 2:14
0

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.

0

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

1
  • I did. Unfortunately they are not lisp code scripts, but shell utilities.
    – M-V
    Aug 9, 2010 at 2:53
0

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
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.