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: Pascal J. Bourguignon
Subject: Re: Redefining functions and variables
Date: Wed, 08 Dec 2010 15:21:35 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

Andreas Politz <politza@fh-trier.de> writes:

> Elena <egarrulo@gmail.com> writes:
>
>> On Jul 28, 7:51 am, Elena <egarr...@gmail.com> wrote:
>>> > Of course this leads to an endless recursive loop, expanding your macro
>>> > again and again ...
>>>
>>> Then I should have tested the macro with `macroexpand-all' instead of
>>> `macroexpand'. However, I've tried using the macro, and it seemed to
>>> work, albeit it choked on the unquoted symbol passed to `fboundp'.
>>
>> I think it seemed to work because the macro was interpreted, therefore
>> it was expanded only once before the failure.
>
> Don't know, but defining `defun' as a macro usually deletes the original
> subst (which is a special form, which is kind of like a macro).
>
> (defvar defun-subst (symbol-function 'defun))
>
> (defmacro defun (name args &rest body)
>   `(defun ,name ,args ,@body))
>
> (defun foo ())
> ;; Enters the debugger because of recursion limit reached.
>
> ;; Restore original defun
> (fset 'defun defun-subst)

Another way:

(defvar old-defun 'defun) ; the symbol!
(unintern 'defun)

(defmacro defun (name args &rest body)
  `(progn
      (message "defining %S" name)
      (,old-defun ,name ,args ,@body)))

In this case there's no infinite recursion.

      
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

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