Subject: Re: macros, &REST and REMF
From: (Rob Warnock)
Date: Sat, 30 Nov 2002 02:58:40 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
Sam Steingold  <> 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 Warnock, PP-ASEL-IA		<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607