[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Redefining defun

Blake McBride

8/27/2015 12:03:00 PM

Hi,

I am trying to re-define defun while still being able to use the old
version. For example, presuming I am in the common-lisp-user package, I
am doing:

(defmacro defun (&rest args)
`(progn
(common-lisp:defun ,(car args)
,(cadr args)
,@(cddr args))
(setf (get ',(car args) 'FNCELL)
'(lambda ,(cadr args) ,@(cddr args)))
',(car args)))

It works if I name my macro defun2, but doesn't work as shown. Not sure
what is going on. Any help would sure be appreciated.

Thanks.

Blake McBride
3 Answers

Pascal J. Bourguignon

8/27/2015 1:30:00 PM

0

Blake McBride <blake1024@gmail.com> writes:

> I am trying to re-define defun while still being able to use the old
> version. For example, presuming I am in the common-lisp-user package,
> I am doing:
>
> (defmacro defun (&rest args)
> `(progn
> (common-lisp:defun ,(car args)
> ,(cadr args)
> ,@(cddr args))
> (setf (get ',(car args) 'FNCELL)
> '(lambda ,(cadr args) ,@(cddr args)))
> ',(car args)))
>
> It works if I name my macro defun2, but doesn't work as shown. Not
> sure what is going on. Any help would sure be appreciated.

Try:

(in-package "COMMON-LISP-USER)
(symbol-package 'defun)

What do you get?
What does that mean?


Have a look at SHADOW, or DEFPACKAGE :SHADOW.
--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Kaz Kylheku

8/27/2015 2:21:00 PM

0

On 2015-08-27, Blake McBride <blake1024@gmail.com> wrote:
> Hi,
>
> I am trying to re-define defun while still being able to use the old
> version. For example, presuming I am in the common-lisp-user package, I
> am doing:
>
> (defmacro defun (&rest args)
> `(progn
> (common-lisp:defun ,(car args)

If this doesn't work, it must be because the unqualified symbol defun
is actually common-lisp:defun.

This is the case in common-lisp-user by default, because it is set up
to use the common-lisp package; all external symbols in common-lisp
are *visible* in common-lisp-user.

There is no common-lisp-user:defun.

We can ensure that a symbol called "DEFUN" is actually present in
common-lisp-user, and also that it defeats the one that is otherwise
visible from common-lisp:

COMMON-LISP-USER> (shadow 'defun)

Done! Now defun is common-lisp-user::defun, and so you can do:

COMMON-LISP-USER> (defmacro defun (...) `(cl:defun ...))

The shadow function ensures that the symbol is present in the package (if not
already) and adds it to the shadowing list: the list of symbols which
automatically win visibility clashes arising from the use of use-package.
That is to say, common-lisp-user continues to use common-lisp,
but because it contains a shadowing symbol defun, common-lisp:defun is
not visible any more through common-lisp-user; rather, the shadowing symbol is.

Blake McBride

8/27/2015 4:11:00 PM

0

SHADOW did the trick. Thanks!!

Blake


On 08/27/2015 09:20 AM, Kaz Kylheku wrote:
> On 2015-08-27, Blake McBride <blake1024@gmail.com> wrote:
>> Hi,
>>
>> I am trying to re-define defun while still being able to use the old
>> version. For example, presuming I am in the common-lisp-user package, I
>> am doing:
>>
>> (defmacro defun (&rest args)
>> `(progn
>> (common-lisp:defun ,(car args)
>
> If this doesn't work, it must be because the unqualified symbol defun
> is actually common-lisp:defun.
>
> This is the case in common-lisp-user by default, because it is set up
> to use the common-lisp package; all external symbols in common-lisp
> are *visible* in common-lisp-user.
>
> There is no common-lisp-user:defun.
>
> We can ensure that a symbol called "DEFUN" is actually present in
> common-lisp-user, and also that it defeats the one that is otherwise
> visible from common-lisp:
>
> COMMON-LISP-USER> (shadow 'defun)
>
> Done! Now defun is common-lisp-user::defun, and so you can do:
>
> COMMON-LISP-USER> (defmacro defun (...) `(cl:defun ...))
>
> The shadow function ensures that the symbol is present in the package (if not
> already) and adds it to the shadowing list: the list of symbols which
> automatically win visibility clashes arising from the use of use-package.
> That is to say, common-lisp-user continues to use common-lisp,
> but because it contains a shadowing symbol defun, common-lisp:defun is
> not visible any more through common-lisp-user; rather, the shadowing symbol is.
>