Reputation: 783
I use the "pregexp" package for regular expression operations in SBCL. Because the functions is not defined in a package, I have the codes below to wrap it:
--------------- in the file "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))
I put codes in the initilization file "~/.sbclrc", to load the "foo.lisp" on starting. That's just OK by now, and no error when I start SBCL.
Then I noticed that every time I reload "foo.lisp", there are warnings that the functions already exported, so I change the codes:
--------------- in the file "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*)
)
I only wrap the codes in a `progn' block, but every time I start SBCL, there is error:
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]
So, what should I do now?
PS, the environments: SBCL x86 1.1.4 On Windows Server 2003 32bits
Upvotes: 0
Views: 451
Reputation: 85853
Rainer Joswig's answer mentions some of the things that occur with the reader, interning, and exporting, but I wonder if the problem you're having isn't more easily avoided by using the :export
clause of defpackage
. If you use it, you can write your defpackage
form as:
(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))
Even if those symbols name functions, there's no requirement to define those functions before exporting the symbols with which they are associated. (I only mention that because the code in the question defines the package, then loads (presumably) function definitions, then exports symbols. Things don't need to happen in that order. It's fine to, e.g., define the package, export the symbols, then define the functions.)
Upvotes: 0
Reputation: 139261
The reader reads the PROGN
form as a single form in the current package. Symbols are from that package then.
So try to export COMMON-LISP-USER::PREFEXP
symbol from the package PREGEXP
.
You need to make sure that you export the right symbol (which is in the correct package).
Upvotes: 1