From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: lawrence mitchell Newsgroups: gmane.emacs.help Subject: Re: Difficult macro question: Doing custom `let' Date: Mon, 18 Aug 2003 19:20:07 +0100 Organization: funfunfun Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1061231548 675 80.91.224.253 (18 Aug 2003 18:32:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 18 Aug 2003 18:32:28 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 18 20:32:27 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19oonr-0000Nx-00 for ; Mon, 18 Aug 2003 20:32:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19oonB-0002Da-Ie for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Aug 2003 14:31:45 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!sybil.ph.ed.ac.UK!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 47 Original-NNTP-Posting-Host: sybil.ph.ed.ac.uk (129.215.73.53) Original-X-Trace: news.uni-berlin.de 1061230809 2507643 129.215.73.53 (16 29) X-No-Yes: No Mail-Copies-To: nobody User-Agent: Gnus/5.090011 (Oort Gnus v0.11) Emacs/20.4 (sparc-sun-solaris2.6) Cancel-Lock: sha1:ZCbWMtoFl6EpN3qExInkZKhg3IY= Original-Xref: shelby.stanford.edu gnu.emacs.help:115992 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:11908 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:11908 Jari Aalto+mail.emacs wrote: [...] given list => '(a b c), get (let (a b c) ...) > Now the problem is, How Do I make a macro that does exactly that above? > The macro would be called inside function body: > (defun my-test () > (my-let-transform list > (message "It worked."))) > Which should be after macroexpand: > (defun my-test () > (let (a > b > b) > (message "It worked."))) If you do (require 'cl), you can try something like this: (defmacro* my-transform-list ((&rest vars) &body body) ;; If VARS is a variable, assume we wanted its value. ;; otherwise, we just take it as a literal list. ;; This means that both (my-transform-list (a b) ...) ;; and (my-transform-list foo ...) work (assuming foo is boundp). (ignore-errors (setq vars (symbol-value vars))) `(let ,vars ,@body)) (macroexpand '(my-transform-list (a b c) (message "It works."))) => (let (a b c) (message "It works.")) but also: (setf list '(a b c)) (macroexpand '(my-transform-list list (message "It works."))) => (let (a b c) (message "It works.")) Note that there is no need to quote the list of variables if you give them literally. -- lawrence mitchell