packages - common lisp: got different result with SBCL after saving image -


(it's first time me post question here, searched didn't found useful information....)

i found interesting (which confused me whole damn morning) thing in common lisp.

i'm using sbcl 1.1.18 running on gentoo/linux. here's problem:

suppose there's package named eql-test have asd file, package.lisp , main.lisp (quite common config). inside main.lisp, there's 1 single function:

    (defun main ()       (format t "~a~%" (eql 'hello (read-from-string "hello")))) 

now, if run:

    sbcl --eval "(progn (load \"main.lisp\") \       (sb-ext:save-lisp-and-die \"eql-test\" :toplevel #'main \       :executable t))" 

and run "eql-test" binary, we'll beautiful t.

however, if use file named "make.lisp" contains:

    (asdf:load-system 'eql-test)     (sb-ext:save-lisp-and-die "eql-test2"           :toplevel #'eql-test:main           :executable t) 

and run:

    sbcl --load "make.lisp" 

then run binary "eql-test2", give nil.

i don't understand why same code gives different result (definitely second 1 not correct). because it's implicit bug of asdf? or there's wrong code?

thanks help! :)

basic rule: when in doubt, control package used in source code, in io operations, when creating new symbols, when searching symbols, ...

if read string, should make sure symbol created in correct package. 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 in cl-user package.

let's create 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 variable:

cl-user 5 > (let ((*package* (find-package "bar")))               (read-from-string "foo")) bar::foo 3 

above: foo in package bar.

also make sure source code a defined package... make sure package not changed different ways load code...


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -