I was reading The Complete Idiot’s Guide to Common Lisp Packages, and I've made a new package called named BOB using make-package. After (in-package :bob), though, I can't use any symbol that I'd been able to use while “in” the CL-USER package. For example:

CL-USER> (make-package :bob)
CL-USER> (in-package :bob)
BOB> (+ 1 2) 
;; caught COMMON-LISP:STYLE-WARNING:
;; undefined function +

I also tried to use CL-USER package, as follows, but I get the same result:

CL-USER> (make-package :bob :use '(:cl-user))

How can I use symbols defined in CL-USER?

有帮助吗?

解决方案

CL-USER usually does not export anything. So it's useless to use it. That a package uses other packages, does not mean it exports anything. These are independent functionalities.

Since SBCL introduced an incompatibility to common practice (though not the standard), you have to specify the packages to use all the time - there is no default. Before that, there was a default (CLtL1 defined it that way). Now SBCL uses no package and this is allowed by the ANSI CL standard.

If you want a package with a use list like CL-USER, do this instead:

CL-USER 1 > (package-use-list "CL-USER")
(#<The COMMON-LISP package, 2/4 internal, 978/1024 external>
 #<The HARLEQUIN-COMMON-LISP package, 3/4 internal, 271/512 external>
 #<The LISPWORKS package, 67/128 internal, 228/256 external>)

CL-USER 2 > (make-package "FOO" :use (package-use-list "CL-USER"))
#<The FOO package, 0/16 internal, 0/16 external>

CL-USER 3 > (in-package "FOO")
#<The FOO package, 0/16 internal, 0/16 external>

FOO 4 > (+ 3 4)
7

其他提示

Use defpackage, not make-package.

(defpackage :example
  (:use :cl)
  (:export #:thing))

(in-package :example)
(defun thing () )

I didn't answer your question, because defpackage is the standard for the vast majority of code.

Checking your code with CCL, CLISP, and SBCL reveal variances in behavior. Hm.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top