Re: defining many similar functions using macros

From:

David Kastrup

Subject:

Re: defining many similar functions using macros

Date:

Mon, 04 Oct 2004 18:30:04 +0200

User-agent:

Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux)

Kevin Rodgers <address@hidden> writes:
> As someone else pointed out, the solution is to use the fset function
> instead of the macro:
>
> (defmacro define-tex-symbol (name)
> `(fset (intern (concat "tex-" ,name))
> (lambda ()
> (interactive)
> (insert "\\" ,name))))
It is completely pointless to use a macro here. The only effect you
gain by it is side effects from multiple evaluation of `name'. Just
use defun here: you can't hope to gain much efficiency from avoiding
just such a tiny bit of expansion in an otherwise complicated
operation.
To wit:
(defun define-tex-symbol (name)
(fset (intern (concat "tex-" name))
`(lambda () (interactive)
(insert "\\" ,name))))
If you really want the "optimization", use defsubst instead of defun.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum