Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
857 stars 103 forks source link

Can't (in-package ...) from ccl-init.lisp #480

Closed snunez1 closed 8 months ago

snunez1 commented 8 months ago

In my .sbclrc file, I end with (in-package :foo) to put me in the package I usually work from, however it appears that in CCL this doesn't work. The rest of the init file is executed, but not the in-package form. This is on Windows 10, CCL 1.12.2.

Has anyone else seen this or have a workaround?

informatimago commented 8 months ago

1- this is normal, because ccl-init.lisp is loaded with CL:LOAD.

2- one easy workaround is to use the -e option:

ccl -e '(in-package "FOO")'

you can put that in a script if you want to do it a lot:

cat > ccl-foo <<EOF
#!/bin/bash
ccl -e '(in-package "FOO")'
EOF
chmod 755 ccl-foo

3- if you want to change this behavior, it's implemented in startup-ccl in level-1/l1-boot-lds.lisp. Instead of (load init-file :if-does-not-exist nil :verbose nil), you could write: (eval-file init-file :if-does-not-exist nil :verbose nil) with something like:

(defun eval-file (file &key verbose)
  (with-open-file (script file :if-does-not-exist nil)
    (when script
      (progn
        (setf *package* (find-package "COMMON-LISP-USER"))
        (setf *print-array* t)
        (setf *print-base* 10)
        (setf *print-case* :upcase)
        (setf *print-circle* nil)
        (setf *print-escape* t)
        (setf *print-gensym* t)
        (setf *print-length* nil)
        (setf *print-level* nil)
        (setf *print-lines* nil)
        (setf *print-miser-width* nil)
        #+ccl (setf *print-pprint-dispatch* ccl::*standard-pprint-dispatch-table*)
        (setf *print-pretty* nil)
        (setf *print-radix* nil)
        (setf *print-readably* t)
        (setf *print-right-margin* nil)
        (setf *read-base* 10)
        (setf *read-default-float-format* 'single-float)
        (setf *read-eval* t)
        (setf *read-suppress* nil)
        (setf *readtable* (copy-readtable #-ccl nil #+ccl ccl::%standard-readtable%))
        #+ccl (setf ccl:*print-abbreviate-quote* nil)
        #+ccl (setf ccl:*print-structure* t)
        #+ccl (setf ccl:*print-simple-vector* nil)
        #+ccl (setf ccl:*print-simple-bit-vector* nil)
        #+ccl (setf ccl:*print-string-length* nil))
      (loop
        :for form := (handler-case (read script nil script)
                       (error (err)
                         (format *error-output* "ERROR: ~A~%" err)
                         (return-from eval-file nil)))
        :until (eql form script)
        :do (handler-case (eval form)
              (error (err)
                (format *error-output* "ERROR: ~A~%" err)
                (return-from eval-file nil)))))))
snunez1 commented 8 months ago

Well, first, thank you for the quick response.

If I'm the only one that needs this, I suppose it can be closed. However, I suggest we leave it open for a while to see if it gets any upvotes or likes and, if not, then I'll close it.

xrme commented 8 months ago

There's a function called ccl:set-development-environment that CCL hackers sometimes put in their init files. See https://github.com/Clozure/ccl/blob/c197bd0d9f5e861714db1369f714591bd835b572/lib/prepare-mcl-environment.lisp#L67-L79

It calls an internal operator that resets the outmost binding of *package*.

snunez1 commented 8 months ago

@xrme, thanks, that works well, and is useful for other environment setup purposes. I'll mark as closed and hopefully anyone else with the problem will find this issue.