我在SBCL中使用"pregexp“包进行正则表达式操作。因为这些函数不是在包中定义的,所以我有以下代码来包装它:
-在文件"foo.lisp“中
(defpackage :pregexp
(:use :common-lisp)
(:documentation "Portable Regular Expression Library")
(:nicknames :pre))
(in-package :pregexp)
(load (merge-pathnames "libs/pregexp/pregexp" CL-USER:*x-code-path*))
(export '(pregexp
pregexp-match-positions
pregexp-match
pregexp-split
pregexp-replace
pregexp-replace*
pregexp-quote))我将代码放在初始化文件"~/.sbclrc“中,以便在启动时加载"foo.lisp”。现在一切正常,当我启动SBCL时也没有错误。
然后我注意到,每次我重新加载"foo.lisp“时,都会出现函数已经导出的警告,所以我更改了代码:
-在文件"foo.lisp“中
#-pregexp
(progn
(defpackage :pregexp
(:use :common-lisp)
(:documentation "Portable Regular Expression Library")
(:nicknames :pre))
(in-package :pregexp)
(load (merge-pathnames "libs/pregexp/pregexp" CL-USER:*x-code-path*))
(export '(pregexp
pregexp-match-positions
pregexp-match
pregexp-split
pregexp-replace
pregexp-replace*
pregexp-quote))
(pushnew :pregexp *features*)
)我只将代码包装在一个“`progn”块中,但每次启动SBCL时,都会出现错误:
debugger invoked on a SB-KERNEL:SIMPLE-PACKAGE-ERROR in thread
#<THREAD "main thread" RUNNING {23EF7A51}>:
These symbols are not accessible in the PREGEXP package:
(COMMON-LISP-USER::PREGEXP COMMON-LISP-USER::PREGEXP-MATCH-POSITIONS
COMMON-LISP-USER::PREGEXP-MATCH COMMON-LISP-USER::PREGEXP-SPLIT
COMMON-LISP-USER::PREGEXP-REPLACE COMMON-LISP-USER::PREGEXP-REPLACE*
COMMON-LISP-USER::PREGEXP-QUOTE)
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [CONTINUE] IMPORT these symbols into the PREGEXP package.
1: [RETRY ] Retry EVAL of current toplevel form.
2: Ignore error and continue loading file "C:\\test\\bar.lisp".
3: [ABORT ] Abort loading file "C:\\test\\bar.lisp".
4: Retry EVAL of current toplevel form.
5: Ignore error and continue userinit file "C:\\user\\Dropbox\\.sbclrc".
6: Abort userinit file "C:\\user\\Dropbox\\.sbclrc".
7: Skip to toplevel READ/EVAL/PRINT loop.
8: [EXIT ] Exit SBCL (calling #'EXIT, killing the process).
((FLET SB-IMPL::THUNK :IN EXPORT))
0] 那么,我现在应该做什么呢?
PS,环境: Windows Server2003 32位上的SBCL x86 1.1.4
发布于 2013-05-23 17:47:16
阅读器将PROGN表单作为当前包中的单个表单读取。符号就是那个包里的。
因此,尝试从PREGEXP包中导出COMMON-LISP-USER::PREFEXP符号。
您需要确保导出正确的符号(位于正确的包中)。
发布于 2013-05-23 22:51:59
Rainer Joswig's answer提到了读者、实习生和导出过程中发生的一些事情,但我想知道使用defpackage的:export子句是否可以更容易地避免您遇到的问题。如果使用它,您可以将defpackage表单编写为:
(defpackage :pregexp
(:use :common-lisp)
(:documentation "Portable Regular Expression Library")
(:nicknames :pre))
(:export #:pregexp ; or :pregexp, or "PREGEXP"
#:pregexp-match-positions
#:pregexp-match
#:pregexp-split
#:pregexp-replace
#:pregexp-replace*
#:pregexp-quote))即使这些符号命名了函数,在导出与其关联的符号之前,也不需要定义这些函数。(我只提到这一点,因为问题中的代码定义了包,然后加载(假设)函数定义,然后导出符号。事情不需要按这个顺序发生。例如,可以定义包,导出符号,然后定义函数。)
https://stackoverflow.com/questions/16706647
复制相似问题