8 Generating a Single Self-Sufficient File

Sometimes one file beats a tree: mailing a library to a colleague, APPLOADing on a locked-down machine, pasting into a console. Concatenate the system into a single source file:

(alpm-concatenate-system "geometry" "d:/out/geometry-all.lsp" nil nil)

The file contains every source of ‘geometry’ in dependency order, each section labeled with a banner comment naming its original file. Dependencies are handled by the fourth argument:

;; default: dependencies as (alpm-load-system ...) forms at the top
;; -- small file, but loading it requires ALPM + registry.
(alpm-concatenate-system "geometry" "d:/out/geometry-all.lsp" nil nil)

;; monolithic: dependency sources concatenated in too -- the file
;; needs nothing at all, one load brings in everything.
(alpm-concatenate-system "geometry" "d:/out/geometry-full.lsp" "cp1252" T)

The third argument is the encoding of the generated file (default: the system’s declared ‘encoding’); every source is transcoded from its own declared encoding, and a character that does not fit the target encoding is a generation error, never mojibake.

Caveats (also written into the generated header): the value of ‘load’ is the last form of the last file, not of each file; code that locates siblings of its own source file behaves differently once everything is one file; and a monolithic file redefines every included dependency at load time — in a session that manages libraries with ALPM, prefer the default form, which lets ‘alpm-load-system’ keep each dependency loaded exactly once.