Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run SBCL code under a Unix-like operating system in a convenient way?

Tags:

(David James both wrote the question and an answer. I'll edit it to conform to Stackoverflow standards.)

Using SBCL you can compile Lisp code to machine code.

Like Java, .net, C++ and even C you will need the runtime. So there are two ways to compile Common Lisp code.

First is to make huge binaries which is explained in SBCL documentation. No SBCL needed on target machine.

The other way is a more flexible one, which is to create machine code in a fasl (FASt Load) format. The SBCL runtime is needed on the target machine.

How does the second way work under a Unix-like operating system?

like image 565
David James Avatar asked Jan 29 '12 18:01

David James


People also ask

How does Sbcl work?

SBCL provides a recursive event loop ( serve-event ) for doing non-blocking IO on multiple streams without using threads. SBCL allows restricting the execution time of individual operations or parts of a computation using :timeout arguments to certain blocking operations, synchronous timeouts and asynchronous timeouts.

How do I exit Sbcl?

To quit SBCL, type (quit) .


1 Answers

(Answer by David James:)

We are going to make two commands in our system: one for batch compiling Lisp code and the other for easily running Lisp code:

Using your favorite editor, open a file called sbcl.compile. The content should be:

    #!/bin/bash     sbcl --noinform --eval "(compile-file \"$1\")" --eval "(quit)" > /dev/null 

Now to compile Lisp files use:

    # sbcl.compile hello.lisp 

This will create a hello.fasl file.

Now to easily run these files, we create a new command. Using your favorite editor open a file called sbcl.run. The content should be:

    #!/bin/bash     sbcl --noinform --load "$1" --quit --end-toplevel-options "$@" 

Now you may invoke sbcl.run hello.fasl to run the native code.

    # sbcl.run hello.fasl 

Details are described in the SBCL manual: Starting SBCL

like image 83
4 revs, 3 users 96% Avatar answered Oct 09 '22 00:10

4 revs, 3 users 96%