Overriding cl package symbols

Andy Peterson andy.arvid at gmail.com
Mon Jun 10 15:37:00 UTC 2019

parenscript does not redefine "defun", it imports cl:defun and exports it

CL-USER> (eq 'ps:defun 'cl:defun )

Exporting has nothing to do with the package lock.  it refers to when you
try to redefine cl:defun.

You can define your own defun in your own package. The library *Series *does
this but it does not export it.

from s-package.lisp

(defpackage #:series
    (:use #:cl)

   #:let #:let* #:multiple-value-bind #:funcall #:defun
   #+(or cmu scl) #:collect #+(or cmu scl) #:iterate)

from s-code.lisp:

(defmacro defun (name lambda-list &environment *env* &body body)
  (if (dolist (form body)
        (cond ((and (stringp form) (eq form (car body))))
              ((and (consp form) (eq-car form 'declare))
               (if (assoc 'optimizable-series-function (cdr form)) (return
              (t (return nil))))
      (define-optimizable-series-fn name lambda-list body)
    (progn (undefine-optimizable-series-fn name)
           `(cl:defun ,name ,lambda-list
              . ,body))))

you could export it, put it would generate conflicts when you use it.

SERIES> (export 'defun)
SERIES> (in-package :cl-user)
CL-USER> (use-package :series)
USE-PACKAGE #<PACKAGE "SERIES"> causes name-conflicts in
#<PACKAGE "COMMON-LISP-USER"> between the following symbols:
   [Condition of type NAME-CONFLICT]
See also:
  Common Lisp Hyperspec, [:section]
; Evaluation aborted on #<NAME-CONFLICT {1002576393}>.

I hope this clarifies it for you.

andy peterson

On Sun, 9 Jun 2019 at 15:39, James Gunn <jgunn987 at gmail.com> wrote:

> Hello,
> I have been reading the source code for parenscript and I am keen to find
> out how you override locked symbols? In the parenscript package there are
> exports such as "#:defun". I have tried myself to create my own package
> that exports defun but i get the following error message(using SBCL)
> "Lock on package COMMON-LISP violated when proclaiming DEFUN as a function"
> I'd be very interested in finding out how you got around this.
> Thank you,
> James Gunn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20190610/0bdf0aec/attachment.html>

More information about the parenscript-devel mailing list