unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: David Kastrup <dak@gnu.org>
Subject: Re: defining many similar functions using macros
Date: Mon, 04 Oct 2004 18:30:04 +0200	[thread overview]
Message-ID: <x5vfdq78fn.fsf@lola.goethe.zz> (raw)
In-Reply-To: 41617275.5000108@yahoo.com

Kevin Rodgers <ihs_4664@yahoo.com> 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

  reply	other threads:[~2004-10-04 16:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.984.1096774354.2017.help-gnu-emacs@gnu.org>
2004-10-03  5:31 ` defining many similar functions using macros Klaus Berndl
2004-10-03  8:18 ` David Kastrup
2004-10-04 15:55 ` Kevin Rodgers
2004-10-04 16:30   ` David Kastrup [this message]
2004-10-03  3:25 Joe Corneli
2004-10-03  6:49 ` Daniel Pittman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x5vfdq78fn.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).