Subject: Re: macros, &REST and REMF
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 30 Nov 2002 02:58:40 -0600
Newsgroups: comp.lang.lisp
Message-ID: <wK-cnXfOnZJd4HWgXTWcqA@giganews.com>
Sam Steingold  <sds@gnu.org> wrote:
+---------------
| Is this the right idiom:
| (defmacro with-foo ((&key foo) &body body)
|   `(... ,foo ... ,@body))
| 
| (defmacro with-foo-bar ((&rest opts &key bar &allow-other-keys) &body body)
|   (remf opts :bar)
|   `(with-foo (,@opts)
|      ... ,bar ... ,@body))
+---------------

Side question for the group: What are the rules for a &REST arg
in macros? If they're the same as functions, then could you possibly
get in trouble with Sam's idiom due to REMF destructively modifying
the "opts" list? That is, does one really need to do this instead?

  (defmacro with-foo-bar ((&rest opts &key bar &allow-other-keys) &body body)
    (let ((mutable-opts (copy-list opts)))
      (remf mutable-opts :bar)
      `(with-foo (,@mutable-opts)
         ... ,bar ... ,@body)))


-Rob

-----
Rob Warnock, PP-ASEL-IA		<rpw3@rpw3.org>
627 26th Avenue			<URL:http://www.rpw3.org/>
San Mateo, CA 94403		(650)572-2607