Search code examples
sbclslime

slime v.2014-04-27 sbcl v.1.2.0 lisp in-package does not change *package* after compilation and loading command C-c C-k


This is the code:

(defpackage :morse
  (:use :common-lisp))

(in-package :morse)
...

When I use C-c C-k (Compile/Load file):

CL-USER> *package*
#<PACKAGE "COMMON-LISP-USER">
; compiling file "/home/frederik/Lisp/Code/mycode/marco_baringer.lisp" (written 16 JUN 2014 11:30:15 AM):

; /home/frederik/Lisp/Code/mycode/marco_baringer.fasl written
; compilation finished in 0:00:00.025
CL-USER> *package*
#<PACKAGE "COMMON-LISP-USER">
CL-USER> 

I am still in package "COMMON-LISP-USER" when the command "(in-package :morse)" is given in the source code. I should be in "MORSE" I think because when I give the command in the REPL:

...
CL-USER> (in-package :morse)
#<PACKAGE "MORSE">
MORSE> *package*
#<PACKAGE "MORSE">
MORSE> 
...

Any idea? Am I wrong?


Solution

  • From: Nick Levine ravenbrook.com> Subject: Re: SLIME compile and load file REPL stays at "CL-USER" with "(in-package :xyz)" in code and not "XYZ" Newsgroups: gmane.lisp.slime.devel Date: 2014-06-17 08:12:34 GMT (15 minutes ago)

    From: Frederik Cheeseman evonet.be> Date: Tue, 17 Jun 2014 07:54:20 +0000 (UTC)

    When I do C-c C-k (SLIME compile/load file) the REPL stays at "CL-USER". Shouldn't it switch to "MORSE" because of the "(in-package :morse)" code line?

    No (and this applies to CL in general, not just to SLIME). This is because, according to the spec, "load binds readtable and package to the values they held before loading the file." In effect:

    (defun load (file &key ...)
      (let ((*package* *package*))
        (in-load file ...)))
    
    • n