I'm new to Lisp so when I wrote the function in SBCL
(defun subst (new old l)
(cond
((null l) '())
((eq old (car l)) (cons new (cdr l)))
((cons (car l) (subst new old (cdr l))))))
it gives error SYMBOL-PACKAGE-LOCKED-ERROR,a Style-Warning and a Warning, please help to resolve it
You're trying to redefine
cl:subst
. According to §11.1.2.1.2 of the HyperSpec, it's undefined what happens when you try to do that. Most implementations have some sort of package lock which prevents such redefinitions. You can get around those, by unlocking the package, but it would be better in this case to either use a name other thansubst
(e.g.,my-subst
), or to define a new package, saymy-cl
, that shadowscl:subst
and definemy-cl:subst
instead.The error that SBCL gives is actually rather informative and provides a reference to the HyperSpec page that I linked to above, as well as the Chapter 11. Package Locks from the SBCL manual: