From: Daniel Pittman <daniel@rimspace.net>
Subject: Re: defining many similar functions using macros
Date: Sun, 03 Oct 2004 16:49:22 +1000 [thread overview]
Message-ID: <87zn34gutp.fsf@enki.rimspace.net> (raw)
In-Reply-To: E1CDx0D-0002sj-00@linux183.ma.utexas.edu
On 3 Oct 2004, Joe Corneli wrote:
> 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:
[...]
> 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:
[...]
> triggers an error:
[... when run from `dolist' ...]
> 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.
Indeed. The solution suggested elsewhere in the thread makes the macro
expansion work as expected, but why bother with that hoop - just write
the code directly:
(dolist (name '("alpha" "beta"))
(fset (intern (concat "tex-" name))
`(lambda () (interactive) (insert "\\" ,name))))
Note the backquote is needed to use the value of name, rather than the
symbol, but that cuts out the macro expansion middle-man nicely.
Daniel
--
We live in a hallucination of our own devising.
-- Alan Kay
next prev parent reply other threads:[~2004-10-03 6:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-03 3:25 defining many similar functions using macros Joe Corneli
2004-10-03 6:49 ` Daniel Pittman [this message]
[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
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=87zn34gutp.fsf@enki.rimspace.net \
--to=daniel@rimspace.net \
/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).