2 Customizing the Lisp Environment
"lisp-init.lisp"
or"lisp-init.xbin"
and must be located in your home directory. The extension.xbin
denotes a binary file that has been compiled from the source.lisp
file. See Section 2.1.4 in The User's Guide to find out the binary file extension for your platform. When you invoke Lisp, by default your home directory is first searched for a file named"lisp-init.xbin"
and then for a file named"lisp-init.lisp"
. If the file in question exists, it is loaded according to the conventions established by the function load
.
See Chapter 7, "Additional Extensions to Common Lisp" for a description of the functionload
, which loads files into a Lisp image, and for information about changing its behavior.
Any Lisp expression in the initialization file is evaluated when the file is loaded. Thus, you can include expressions that set compilation switches, expand memory, change the value of print variables, or alter the default environment in other ways that are more suited to your needs.
For example, you could set parameters of the storage allocator as follows:
(defun grow () (change-memory-management :growth-limit 2048) (change-memory-management :expand 50))The following code sets the value of certain variables that are used by the Common Lisp function
write
when it sends the printed representation of Lisp objects to an output stream:(setq *print-level* 100 ) (setq *print-length* 100) (setq *print-array* t) (setq *print-structure* nil) (setq *print-pretty* t)This code sets the value of certain Compiler options:
(compiler-options :file-messages t :undef-warnings t :messages nil)You can use the following functions to switch from the development mode of the Compiler to production mode, and vice versa; you must call these functions from the
user
package. For information about the differences between these Compiler modes, see Chapter 3, "Optimizing Lisp Programs".;;; This function invokes the production mode of the Compiler. (defun prodcomp () (proclaim '(optimize (speed 3) (safety 1) (space 0) (compilation-speed 0))))This example shows how to assign abbreviated names to constructs that you use often:;;; This function invokes the development mode of the Compiler. (defun devcomp () (proclaim '(optimize (speed 0) (safety 3) (space 3) (compilation-speed 3))))
(defun cf (&rest args) (apply #'compile-file args)) (defun cfl (&rest args) (load (apply #'compile-file args))) (defun ld (&rest args) (apply #'load args)) (defun ql (&rest args) (let ((*redefinition-action* nil)) (apply #'load args)))The following example changes the setting of the Common Lisp variable(defun dis (&rest args) (apply #'disassemble args))
*package*
from within the initialization file. Assume that you want to do your work in theNEWTOOLS
package. Because the functionload
dynamically binds*package*
toUSER
before loading the initialization file, you cannot use the Common Lisp special formsetq
to change the value of*package*
successfully; the value of*package*
reverts to theUSER
package afterload
exits. This code uses the internal functionliquid::prompt
and Advice Facility constructs to cause Lisp to start up in theNEWTOOLS
package.
(defadvice (liquid::prompt set-package) () ;; Set the package to NEWTOOLS. (in-package "NEWTOOLS" :use '("LISP" "SYSTEM")) (format t "Working in the package ~S~%" *package*) ;; Remove the advice to restore the original definition of ;; PROMPT. (remove-advice 'liquid::prompt 'set-package :verbose nil) ;; Continue with the original prompt function; that is, print ;; the prompt. (advice-continue))
Generated with Harlequin WebMaker