Compiling to binary

Discussion of Common Lisp
kapalua
Posts: 7
Joined: Tue Feb 16, 2010 3:32 am

Compiling to binary

Post by kapalua » Fri Mar 12, 2010 9:25 am

Hi,

When using Windows, is it possible to compile my lisp programs into binaries so i could run the outside the 'lispbox'?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Compiling to binary

Post by ramarren » Fri Mar 12, 2010 10:23 am

With commercial implementations, yes. With open source implementation usually also yes, although it can be more problematic. I am not familiar with Common Lisps/Lispbox on Windows, but perhaps something on the creating executables CLiki page is applicable.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Compiling to binary

Post by nuntius » Fri Mar 12, 2010 11:38 am

Which lispbox did you download? What are (lisp-implementation-type) and (lisp-implementation-version)?

jjgarcia
Posts: 38
Joined: Mon Oct 13, 2008 2:48 pm

Re: Compiling to binary

Post by jjgarcia » Sat Mar 13, 2010 2:13 pm

kapalua wrote:Hi,

When using Windows, is it possible to compile my lisp programs into binaries so i could run the outside the 'lispbox'?
I do not know about 'lispbox', but ECL (http://ecls.sourceforge.net) can build standalone programs using Microsoft Visual C++ It may be a little bit more complicated to set up than other lisps (help is welcome in creating standalone environments) because it requires building ECL from sources, but it may be worth looking at it.

kapalua
Posts: 7
Joined: Tue Feb 16, 2010 3:32 am

Re: Compiling to binary

Post by kapalua » Mon Mar 15, 2010 3:16 am

(lisp-implementation-type) = "CLISP"
(lisp-implementation-version) = "2.33 (2004-03-17) (built on winsteingoldlap [10.0.19.22])"

What i mean by 'lispbox' is 'lisp-in-a-box' running on XP. Also refered to as SLIME i belivie.

I get a feeling that compiling into binaries are not very common using lisp; is it usually just runned from inside the repl? What about the output the (compile-file) command creates, what can i do with that?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Compiling to binary

Post by ramarren » Mon Mar 15, 2010 8:04 am

kapalua wrote:I get a feeling that compiling into binaries are not very common using lisp; is it usually just runned from inside the repl? What about the output the (compile-file) command creates, what can i do with that?
COMPILE-FILE creates a so called FASL file, which is short for 'FASt Load', which allows loading precompiled code into an image. Those are usually not independently executable, since they depend on the Lisp runtime.

Common Lisp is an image based language. To obtain an independent executable you can save a copy of an image with all your code and data loaded and give it a function to run on startup. On CLISP this is done using a SAVEINITMEM function. Do note that the resulting file will be relatively large (although CLISP generates quite small images compared to other Lisps), since it contains an entire Lisp environment. There are only a few Lisp systems which separate the runtime system from the program, with ECL being the most popular open source one.

kapalua
Posts: 7
Joined: Tue Feb 16, 2010 3:32 am

Re: Compiling to binary

Post by kapalua » Tue Mar 16, 2010 1:18 am

Ok, thank you for clarifying.

From this, my conclusion is that the lisp programs most of the time are runned from inside the lisp enviroment/repl and that if i don't have any very specific reason to create a standalone executable it's not worth doing/no need.

I guess i just have to start coding away. :)

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Compiling to binary

Post by nuntius » Tue Mar 16, 2010 9:12 am

Many implementations have their own way to generate "executables". More commonly, people just write shell scripts (or batch files) that load a "main" file. The usage looks something like clisp --norc -i main.lisp (from foggy memory). On unix, cl-launch can help automate the process.

JamesF
Posts: 98
Joined: Thu Jul 10, 2008 7:14 pm

Re: Compiling to binary

Post by JamesF » Tue Mar 16, 2010 8:05 pm

kapalua wrote:From this, my conclusion is that the lisp programs most of the time are runned from inside the lisp enviroment/repl and that if i don't have any very specific reason to create a standalone executable it's not worth doing/no need.
This is exactly correct: think of it as being like a JVM that you can interact with while it's running.

If you really need something that you can run from the command-line or by double-clicking on an icon, that can be done in one of two ways with SBCL. You can create a command-line script that will pass it run-time arguments that tell it to load a package, run a command, etc. - I use this to automatically start up server processes. You can also use the save-lisp-and-die command to dump an image to disk; this can include the lisp VM, which makes it a self-contained executable; it also makes for a large file.

SLIME is a system that allows Emacs to talk to the running Lisp image; it's part of lisp-in-a-box, but the other parts are the Lisp VM/compiler/interpreter and Emacs, probably along with some useful packages. I'm guessing about the packages because I haven't actually used lisp-in-a-box - I can't stand Emacs, so I just use VILisp and SBCL.

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

Re: Compiling to binary

Post by gugamilare » Wed Mar 17, 2010 5:11 am

SBCL has also the sb-executable extension. It has a function named make-executable which receives a list of pathnames of fasls (and a initial function) and creates an executable script containing those files.

Post Reply