Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp Executable

I've just started learning Lisp and I can't figure out how to compile and link lisp code to an executable.

I'm using clisp and clisp -c produces two files:

  • .fas
  • .lib

What do I do next to get an executable?

like image 728
Alexander Stolz Avatar asked Aug 24 '08 13:08

Alexander Stolz


People also ask

Is Common Lisp compiled?

Lisp is a compiled general purpose language, in its modern use. To clarify: “LISP” is nowadays understood as “Common Lisp” Common Lisp is an ANSI Standard.

Is Sbcl compiled?

For what I saw, SBCL doesn't compile to executable and even there are plugins to do that they do not include the dependencies or they package a lot of garbage making heavy executables. I saw that other implementations of Common Lisp actually compile to executables to perform their work.

How executable is created?

A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.


2 Answers

I was actually trying to do this today, and I found typing this into the CLisp REPL worked:

(EXT:SAVEINITMEM "executable.exe"                  :QUIET t                  :INIT-FUNCTION 'main                  :EXECUTABLE t                  :NORC t) 

where main is the name of the function you want to call when the program launches, :QUIET t suppresses the startup banner, and :EXECUTABLE t makes a native executable.

It can also be useful to call

(EXT:EXIT) 

at the end of your main function in order to stop the user from getting an interactive lisp prompt when the program is done.

EDIT: Reading the documentation, you may also want to add :NORC t (read link). This suppresses loading the RC file (for example, ~/.clisprc.lisp).

like image 65
thekidder Avatar answered Oct 13 '22 22:10

thekidder


This is a Lisp FAQ (slightly adapted):

*** How do I make an executable from my programme?

This depends on your implementation; you will need to consult your vendor's documentation.

  • With ECL and GCL, the standard compilation process will produce a native executable.

  • With LispWorks, see the Delivery User's Guide section of the documentation.

  • With Allegro Common Lisp, see the Delivery section of the manual.

  • etc...

However, the classical way of interacting with Common Lisp programs does not involve standalone executables. Let's consider this during two phases of the development process: programming and delivery.

Programming phase: Common Lisp development has more of an incremental feel than is common in batch-oriented languages, where an edit-compile-link cycle is common. A CL developer will run simple tests and transient interactions with the environment at the REPL (or Read-Eval-Print-Loop, also known as the listener). Source code is saved in files, and the build/load dependencies between source files are recorded in a system-description facility such as ASDF (which plays a similar role to make in edit-compile-link systems). The system-description facility provides commands for building a system (and only recompiling files whose dependencies have changed since the last build), and for loading a system into memory.

Most Common Lisp implementations also provide a "save-world" mechanism that makes it possible to save a snapshot of the current lisp image, in a form which can later be restarted. A Common Lisp environment generally consists of a relatively small executable runtime, and a larger image file that contains the state of the lisp world. A common use of this facility is to dump a customized image containing all the build tools and libraries that are used on a given project, in order to reduce startup time. For instance, this facility is available under the name EXT:SAVE-LISP in CMUCL, SB-EXT:SAVE-LISP-AND-DIE in SBCL, EXT:SAVEINITMEM in CLISP, and CCL:SAVE-APPLICATION in OpenMCL. Most of these implementations can prepend the runtime to the image, thereby making it executable.

Application delivery: rather than generating a single executable file for an application, Lisp developers generally save an image containing their application, and deliver it to clients together with the runtime and possibly a shell-script wrapper that invokes the runtime with the application image. On Windows platforms this can be hidden from the user by using a click-o-matic InstallShield type tool.

like image 21
Luís Oliveira Avatar answered Oct 13 '22 23:10

Luís Oliveira