This chapter will describe how to use the plain-common-lisp project to develop and distribute Common Lisp applications. All the examples can be downloaded from the releases area of plain-common-lisp.
Let’s write a Hello-World application with plain-common-lisp. To do that, one just need to extract the last release of plain-common-lisp project:
The "applications" directory is initially empty:
One first need to create a directory "hello-world" to store the files for the application "hello-world".
Each application contains a directory named "systems". This directory must contain at least one ASDF system. Nothing specific to plain-common-lisp here, this structure is common to most Common Lisp’s projects.
The optional "third-party" directory is not used in this example. It can be used to store third-party systems and third-party binaries (i.e. DLL files).
The file "hello-world.asd" defines the way to compile the source code of the application. The format is documented in the ASDF project.
;;; +----------+-------------------------------------------------------+ ;;; | Info | Value | ;;; +----------+-------------------------------------------------------+ ;;; | Filename | hello-world.asd | ;;; | Project | plain-common-lisp-examples | ;;; +------------------------------------------------------------------+ (asdf:defsystem #:hello-world :description "Hello world for plain-common-lisp" :author "Pascal COMBIER" :license "BSD" :components ((:file "package") (:file "hello-world" :depends-on ("package"))))
The "package.lisp" file describe the package "hello-world" which exports the "main" function:
;;; +----------+-------------------------------------------------------+ ;;; | Info | Value | ;;; +----------+-------------------------------------------------------+ ;;; | Filename | package.lisp | ;;; | Project | plain-common-lisp-examples | ;;; +----------+-------------------------------------------------------+ (defpackage #:hello-world (:use #:common-lisp) (:export #:main))
The file "hello-world.lisp" implements the "main" function.
;;; +----------+-------------------------------------------------------+ ;;; | Info | Value | ;;; +----------+-------------------------------------------------------+ ;;; | Filename | hello-world.lisp | ;;; | Project | plain-common-lisp-examples | ;;; +----------+-------------------------------------------------------+ (in-package :hello-world) ;;--------------------------------------------------------------------;; ;; IMPLEMENTATION ;; ;;--------------------------------------------------------------------;; (defun main () (format t "Hello World!~%"))
It’s trivial to test such application because all the applications in the "applications" directory are automatically registered to ASDF at plain-common-lisp’s startup:
To distribute this application, one way could be to distribute it with its source code. An easy approach would be to duplicate "plain-common-lisp.exe" into "hello-world.exe" and duplicate "configs/plain-common-lisp.cfg" into "configs/hello-world.cfg".
Note that "plain-common-lisp.exe" is actually a copy of the executable from the plain-starter project.
The last step would be to create an application starter file in the applications directory.
hello-world.lisp
(asdf:load-system "hello-world") (hello-world:main)
Executing "hello-world.exe" will have the behavior that everyone expects:
The final step before creating a ZIP file and distribute this application would be to delete the unnecessary files: "plain-common-lisp.exe", "configs/plain-common-lisp.cfg" and remove all the files from the cache directory.
A second way would be to distribute this application as a standalone binary file, without any source code attached. This can be achieved by using the save-lisp-and-die function from SBCL.
(sb-ext:save-lisp-and-die "hello-world-standalone.exe" :toplevel #'hello-world:main :executable t :compression t)
Note that the "compression" flag is not mandatory here. It’s a SBCL feature which is not always enabled on the official SBCL binaries for Windows. The SBCL binaries of plain-common-lisp’s always have this feature activated, allowing to trade a little bit of startup time to get a smaller binary size. Note that since SBCL 2.2.6, the zstd from Facebook is used for the compression. A compressed hello-world will typically take 12.5 MiB and the startup time be negligible.
That’s it! The application can be distributed to its users.
It is possible to change the icon present in the executable file without recompiling the program. The cost-free proprietary program Resource Hacker v4.5.30 has been reported working with plain-common-lisp’s executable files.
All the other examples can be downloaded from the releases area of plain-common-lisp. For each example, the program "make-standalone-executable.exe" will generate a standalone executable from the provided Lisp sources.
All the examples should be a little bit slow to start at the first execution. This is perfectly normal because plain-common-lisp will download and install Quicklisp from the internet and compile it. The "cache" directory will then be populated with the results of the compilation. This could take up to a couple of minutes on old systems. The following executions will be much faster. The executions from the standalone executables will be quite fast.
This example shows how to integrate plain-common-lisp with GNU Emacs and SLIME. "plain-common-lisp-swank.exe" will start a SWANK server so that SLIME could connect to it and interact with plain-common-lisp. More details are available in a dedicated chapter of this document.
This example shows how to use CFFI to access the Win32 API.
This example shows how to use the CL-IUP package with plain-common-lisp.
This example shows how to use the ltk library with plain-common-lisp. LTK will use the Tk binaries from Tcl/Tk and will require the program "wish.exe" to be shipped with the application. "wish.exe" is included with the example.
This example shows how to use the ftw library with plain-common-lisp.
This example simply integrates an example from the "cl-glut-examples" available on Quicklisp.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4