2013-04-30 74 views
1

我是新來的Lisp的,所以當我在SBCLLisp的SYMBOL-PACKAGE-鎖定ERROR

(defun subst (new old l) 
    (cond 
    ((null l) '()) 
    ((eq old (car l)) (cons new (cdr l))) 
    ((cons (car l) (subst new old (cdr l)))))) 

寫的功能,它提供了錯誤符號-PACKAGE-鎖定錯誤,一種風格,警告和警告,請幫忙解決它

回答

4

您正試圖重新定義cl:subst。根據HyperSpec的§11.1.2.1.2,它是不確定的,當你嘗試這樣做時會發生什麼。大多數實現都有某種程序包鎖定,可以防止這種重新定義。您可以通過解鎖軟件包來解決這些問題,但在這種情況下使用subst以外的名稱(例如,my-subst)或定義新的軟件包(如my-cl)會更好,該軟件包會影響cl:subst並定義my-cl:subst

是SBCL給人實際上是相當翔實,並且提供一個參考,我掛到上面的HyperSpec頁,還有Chapter 11. Package LocksSBCL manual錯誤:

* (defun subst (new old l) 
    (cond 
     ((null l) '()) 
     ((eq old (car l)) (cons new (cdr l))) 
     ((cons (car l) (subst new old (cdr l)))))) 
; in: DEFUN SUBST 
;  (SB-INT:NAMED-LAMBDA SUBST 
;   (NEW OLD L) 
;  (BLOCK SUBST (COND ((NULL L) 'NIL) ((EQ OLD #) (CONS NEW #)) ((CONS # #))))) 
; ==> 
; #'(SB-INT:NAMED-LAMBDA SUBST 
;   (NEW OLD L) 
;  (BLOCK SUBST 
;   (COND ((NULL L) 'NIL) ((EQ OLD #) (CONS NEW #)) ((CONS # #))))) 
; 
; caught STYLE-WARNING: 
; The definition has no &KEY arguments, but the proclamation did. 

;  (SUBST NEW OLD (CDR L)) 
; 
; caught WARNING: 
; recursion in known function definition 
;  policy=((COMPILATION-SPEED . 1) (DEBUG . 1) (INHIBIT-WARNINGS . 1) 
;    (SAFETY . 1) (SPACE . 1) (SPEED . 1)) 
;  arg types=(T T T) 
; 
; compilation unit finished 
; caught 1 WARNING condition 
; caught 1 STYLE-WARNING condition 
STYLE-WARNING: redefining COMMON-LISP:SUBST in DEFUN 

debugger invoked on a SYMBOL-PACKAGE-LOCKED-ERROR in thread #<THREAD 
                   "initial thread" RUNNING 
                   {1002978E71}>: 
    Lock on package COMMON-LISP violated when setting fdefinition of SUBST while 
    in package COMMON-LISP-USER. 
See also: 
    The SBCL Manual, Node "Package Locks" 
    The ANSI Standard, Section 11.1.2.1.2