[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
defining many similar functions using macros
From: |
Joe Corneli |
Subject: |
defining many similar functions using macros |
Date: |
Sat, 02 Oct 2004 22:25:37 -0500 |
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.
- defining many similar functions using macros,
Joe Corneli <=