unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* defining many similar functions using macros
@ 2004-10-03  3:25 Joe Corneli
  2004-10-03  6:49 ` Daniel Pittman
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Corneli @ 2004-10-03  3:25 UTC (permalink / raw)


I have a lot of functions that are very similar:

(defun tex-alpha ()
  (interactive)
  (insert "\\alpha"))

(defun tex-beta ()
  (interactive)
  (insert "\\beta"))

...

I would like to define them all in one go:

(dolist (elt '("alpha"
               "beta"
               ...))
  (define-tex-symbol elt))

This seems like a good chance to use a macro.  My first experiment
along these lines fails however, and I could use some help
re-designing it.

This macro works on single elements:

(defmacro define-tex-symbol (name)
  `(defun ,(intern (concat "tex-" name)) ()
     (interactive)
     (insert "\\" ,name)))

E.g. (define-tex-symbol "alpha") ;=> tex-alpha

But 

(dolist (elt '("alpha"
               "beta"))
  (define-tex-symbol elt))

triggers an error:

Debugger entered--Lisp error: (wrong-type-argument sequencep elt)
  concat("tex-" elt)
  (intern (concat "tex-" name))
  (list (quote defun) (intern (concat "tex-" name)) nil (quote (interactive)) (list (quote insert) "\\" name))
...

There seem to be some subtleties associated with macro expansion
that I'm missing here.  Help would be appreciated.

^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <mailman.984.1096774354.2017.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2004-10-04 16:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-03  3:25 defining many similar functions using macros Joe Corneli
2004-10-03  6:49 ` Daniel Pittman
     [not found] <mailman.984.1096774354.2017.help-gnu-emacs@gnu.org>
2004-10-03  5:31 ` Klaus Berndl
2004-10-03  8:18 ` David Kastrup
2004-10-04 15:55 ` Kevin Rodgers
2004-10-04 16:30   ` David Kastrup

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).