help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redefining functions and variables


From: Andreas Politz
Subject: Re: Redefining functions and variables
Date: Wed, 08 Dec 2010 15:21:25 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Elena <egarrulo@gmail.com> writes:

> On 27 Lug, 22:21, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
>> > I wonder whether there is a way to catch such redefinitions whenever
>> > they happen (which also would help when accidentally redefining
>> > something)
>>
>> Not sure what you mean by that.
>
> Let's assume we have two definitions for the same function:
>
> ;; File A (loaded first)
> (defun foo ()
> ...
>
> ;; File B (loaded later)
> (defun foo () ;; This is a redefinition: I'd like to get a warning.
> ...
>
> Since redefining functions is the heart of interactive programming,
> such a warning should be issued only while loading files. That way,
> you could consider whether to rename the second function or to rewrite
> it as an advice (as you suggested).
>

I think `defun' does not take no advice.

> If such a goal can only be achieved by rewriting "defun" and checking
> by means of "fboundp" whether the function has already been defined,
> here is my (failed, as noted) attempt:
>
> (defmacro defun (name args &rest body)
>   `(progn
>      ;; `load-file-name' is not null only if we are loading a file.
>      (when (and load-file-name
>               ;; FAIL: I don't know how to quote the value of `name'.
>               (fboundp ,name))

                (fboundp ',name))

Why not use `quote'.

>        (message "Warning: %s is being redefined in %s."
>               ;; FAIL: I don't know how to quote the value of `name'.
>               (symbol-name ,name)
>               load-file-name)
>        (defun ,name ,args

Of course this leads to an endless recursive loop, expanding your macro
again and again ...

(funcall (symbol-function 'defun) 'foo nil)
does not seem to work either, which would mean that you can't save
`defun's definition.
>
>        ,@body))))
>
> Any suggestions? Thanks.

-ap


reply via email to

[Prev in Thread] Current Thread [Next in Thread]