I am using Steel Bank Common Lisp (SBCL) and have the following issue.
When I run the following code in the REPL (Read-Evaluate-Print Loop):
* (proclaim '(optimize (speed 3)))
* (describe-compiler-policy)
;; as expected, shows that the SPEED quality is 3
It works as expected, showing that the SPEED quality is 3.
However, when I put the proclaim in a file and then load it, no change persists:
;; file: "test.lisp"
(proclaim '(optimize (speed 3)))
;; in REPL
* (proclaim '(optimize (speed 1)))
* (load "test.lisp")
* (describe-compiler-policy)
;; Shows that SPEED quality is 1. I would expect it to be 3.
The Common Lisp HyperSpec states that load resets *package* and *readtable*, but says nothing about declarations.
The behavior you’re experiencing is due to how the proclaim function works in Common Lisp.
The proclaim function is used to specify global declarations at compile-time. When you run (proclaim '(optimize (speed 3))) in the REPL, it sets the optimization policy for the current Lisp image, and the change persists until you explicitly change it again.
However, when you put the proclaim form in a file and load it using (load "test.lisp"), the file is compiled and evaluated in a separate environment. The proclaim form in the file affects the compilation environment of the file itself, but does not affect the global optimization policy of the Lisp image.
To achieve the desired effect of setting the optimization policy globally, you can use the setq function to modify the value of the *default-compiler-options* variable. Here’s an example:
By modifying the value of *default-compiler-options*, you can set the optimization policy globally and have it persist even when loading files.
This behavior is documented in the SBCL manual under the section “2.2.1.2 Standardized Read-Eval-Print Loop Variables” and “4.2 Compiler Policy”. You can find the SBCL manual at http://www.sbcl.org/manual/.