From mboxrd@z Thu Jan  1 00:00:00 1970
Path: main.gmane.org!not-for-mail
From: Joe Corneli <jcorneli@math.utexas.edu>
Newsgroups: gmane.emacs.help
Subject: defining many similar functions using macros
Date: Sat, 02 Oct 2004 22:25:37 -0500
Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Message-ID: <E1CDx0D-0002sj-00@linux183.ma.utexas.edu>
NNTP-Posting-Host: deer.gmane.org
X-Trace: sea.gmane.org 1096773970 9752 80.91.229.6 (3 Oct 2004 03:26:10 GMT)
X-Complaints-To: usenet@sea.gmane.org
NNTP-Posting-Date: Sun, 3 Oct 2004 03:26:10 +0000 (UTC)
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 03 05:25:55 2004
Return-path: <help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org>
Original-Received: from lists.gnu.org ([199.232.76.165])
	by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian))
	id 1CDx0V-00026o-00
	for <geh-help-gnu-emacs@m.gmane.org>; Sun, 03 Oct 2004 05:25:55 +0200
Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.33)
	id 1CDx71-0003MN-Mz
	for geh-help-gnu-emacs@m.gmane.org; Sat, 02 Oct 2004 23:32:39 -0400
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33)
	id 1CDx6u-0003MI-Iu
	for help-gnu-emacs@gnu.org; Sat, 02 Oct 2004 23:32:32 -0400
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33)
	id 1CDx6u-0003M6-5L
	for help-gnu-emacs@gnu.org; Sat, 02 Oct 2004 23:32:32 -0400
Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.33) id 1CDx6u-0003M3-3J
	for help-gnu-emacs@gnu.org; Sat, 02 Oct 2004 23:32:32 -0400
Original-Received: from [146.6.139.124] (helo=dell3.ma.utexas.edu)
	by monty-python.gnu.org with esmtp (Exim 4.34) id 1CDx0H-0005Lz-VZ
	for help-gnu-emacs@gnu.org; Sat, 02 Oct 2004 23:25:42 -0400
Original-Received: from linux183.ma.utexas.edu (mail@linux183.ma.utexas.edu
	[146.6.139.172])
	by dell3.ma.utexas.edu (8.11.0.Beta3/8.10.2) with ESMTP id i933PeF01882;
	Sat, 2 Oct 2004 22:25:40 -0500
Original-Received: from jcorneli by linux183.ma.utexas.edu with local (Exim 3.36 #1
	(Debian)) id 1CDx0D-0002sj-00; Sat, 02 Oct 2004 22:25:37 -0500
Original-To: help-gnu-emacs@gnu.org
X-all-your-base-are-belong-to-us: You are on the way to destruction.
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor <help-gnu-emacs.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/help-gnu-emacs>,
	<mailto:help-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/pipermail/help-gnu-emacs>
List-Post: <mailto:help-gnu-emacs@gnu.org>
List-Help: <mailto:help-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/help-gnu-emacs>,
	<mailto:help-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: main.gmane.org gmane.emacs.help:21016
X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:21016

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.