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:48 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

Elena <egarrulo@gmail.com> writes:

> On Jul 29, 10:03 am, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> the "..." are only used to display the list when print-length or
>> eval-expression-print-length are not nil.  See also print-level and
>> eval-expression-print-level.
>
> Didn't know about this. Thanks.
>
>> %s can format symbols too:
>>
>> (format ">> %s <<" 'example)
>> ;; --> ">> example <<"
>>
>> And you had your the old defun inside the when!
>
> Gosh! What an oversight... Sorry.
>
>> Note: while name is known at macroexpansion time, you should refrain
>> to insert it in the string like this:
>>
>>       (message ,(format "Warning: %s is being redefined in %%s." name) 
>> load-file-name)
>>
>> since name could contain percents and then you'd have build a wrong
>> format string for message.
>
> I don't understand this. Doc about `message' says:
>
>> Note: Use (message "%s" VALUE) to print the value of expressions and
>> variables to avoid accidentally interpreting `%' as format specifiers.
>
> And in fact:
>
> (message "%s" 'example%)
>
> correctly outputs:
>
> "example%"


Notice that I call format (at macroexpansion time), to produce a string such as:

   "Warning: my-function is being redefined in %s"

so that the expaned defun contains:

   (message "Warning: my-function is being redefined in %s" load-file-name)


If you want to do that, you must take into account the possibility of
having percents in the argument so that the generated format string is
still correct.

Of course, if you just wait run-time and pass all the arguments, even
the constant ones, to format (or message) as you did, there's no problem.  

But it's a little unsatisfying in general to be leaving work to be
done at run-time when it could be done at compilation time or
macro-expansion time.  

On the other hand, in this specific case, it is probably better as you
did it, since it avoid creating several strings, and the run-time
execution occurs only in the exception case of a redefinition.

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


reply via email to

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