common lisp: got different result with SBCL after saving image
common-lisp, package
Solution
Basic rule: When in doubt, always control which package is used in source code, in IO operations, when creating new symbols, when searching for symbols, ...
If you read from a string, you should make sure that any symbol created will be in the correct package. You can bind `*package*`:
CL-USER 1 > *package*
#<The COMMON-LISP-USER package, 155/256 internal, 0/4 external>
CL-USER 2 > (read-from-string "FOO")
FOO
3
Above: `FOO` is in the `CL-USER` package.
Let's create a new package:
CL-USER 3 > (defpackage "BAR" (:use "CL"))
#<The BAR package, 0/16 internal, 0/16 external>
Global `*package*` has not changed:
CL-USER 4 > *package*
#<The COMMON-LISP-USER package, 155/256 internal, 0/4 external>
Bind the variable:
CL-USER 5 > (let ((*package* (find-package "BAR")))
(read-from-string "FOO"))
BAR::FOO
3
Above: `FOO` is in the package `BAR`.
Also make sure that any source code is a a defined package... make sure that the package is not changed by different ways to load the code...
Problem
(It's the first time for me to post a question here, I searched but didn't found any useful information....) I found an interesting (which confused me for a whole damn morning) thing in common lisp. I'm using SBCL 1.1.18 running on Gentoo/Linux. Here's my problem: Suppose there's a package named eql-test which have an asd file, a package.lisp and a main.lisp (quite common config). Inside main.lisp, there's only one single function: ``` (defun main () (format t "~a~%" (eql 'hello (read-from-string "hello")))) ``` Now, if we run: ``` sbcl --eval "(progn (load \"main.lisp\") \ (sb-ext:save-lisp-and-die \"eql-test\" :toplevel #'main \ :executable t))" ``` and then run the "eql-test" binary, we'll get an beautiful T. However, if we use another file named "make.lisp" which contains: ``` (asdf:load-system 'eql-test) (sb-ext:save-lisp-and-die "eql-test2" :toplevel #'eql-test:main :executable t) ``` and then run: ``` sbcl --load "make.lisp" ``` then run the binary "eql-test2", it will give an NIL. I don't understand why the same code gives different result (definitely the second one is not correct). Because it's a implicit bug of ASDF? Or there's anything wrong with my code? Thanks for any help! :)