From: R. Whitney Winston
Subject: Argument List
Date: 
Message-ID: <1992Jun19.180359.26825@athena.mit.edu>
I want to define a macro that will take an argument list similar to 
the following:

(defmacro macro-name (name arg0 arg1 &rest options)...)

where the options are lists such as the following

(:foo bar)
(:foobar foobar)

so options is ((:foo bar) (:foobar foobar)) however, I 
want to use the keyword option to assign the values of
foo and foobar.

Here's a simplified version:
(defmacro macro-name (name arg0 arg1 &rest options &key foo)....)

would work for a macro call like

(macro-name name arg0 arg1 :foo bar) 
but I can't figure out how to make it work
for something like

(macro-name name arg0 arg1 (:foo bar))

Any suggestions???

Thanks...
>>whitney

From: Len Charest
Subject: Re: Argument List
Date: 
Message-ID: <1992Jun19.203049.10759@jpl-devvax.jpl.nasa.gov>
In article <······················@athena.mit.edu>, ········@athena.mit.edu (R. Whitney Winston) writes:
	[Given a macro lambda-list with &rest options...]
|> so options is ((:foo bar) (:foobar foobar)) however, I 
|> want to use [&key] to assign the values of
|> foo and foobar.

You can't. You'll either have to change the syntax of your macro or else parse the OPTIONS list yourself as part of the macro expansion.

DEFMACRO does provide a lambda-list destructuring facility (see page 197 in CLtL2) but there is no way to write a valid lambda-list that will support the syntax you want in the macro call.

Here is a framework for parsing the list of OPTIONS:

(loop for (keyword value) in options
      do (case keyword
           (:foo (foo-action value ...))
           (:bar (bar-action value ...))
               . . . etc . . .
           (otherwise (default-action value ...))))

Using this approach you can build the appropriate parts of the macro expansion piecewise.
..................................................
                                  Len Charest, Jr.
                 JPL Artificial Intelligence Group
                          ·······@aig.jpl.nasa.gov
From: David Loewenstern
Subject: Re: Argument List
Date: 
Message-ID: <LOEWENST.92Jun20125507@blaze.rutgers.edu>
In article <······················@jpl-devvax.jpl.nasa.gov> ·······@Aig.Jpl.Nasa.Gov (Len Charest) writes:

>In article <······················@athena.mit.edu>, ········@athena.mit.edu (R. Whitney Winston) writes:
> [Given a macro lambda-list with &rest options...]
>|> so options is ((:foo bar) (:foobar foobar)) however, I 
>|> want to use [&key] to assign the values of
>|> foo and foobar.

> You can't. You'll either have to change the syntax of your macro or
>else parse the OPTIONS list yourself as part of the macro expansion.

You can, but it isn't pretty:

(defun alist-to-plist (alist)
  (reduce #'append alist))

(defmacro foo (a b &KEY foo bar)
   ...)

(defmacro bar (a b &rest args)
  `(foo ,a ,b ,@(alist-to-plist args)))

These opinions are shareware.  If you like the product,
please send your $0.02 to
               David Loewenstern
   <·····@homxc.att.com> || <········@paul.rutgers.edu>
From: Thomas A. Russ
Subject: Re: Argument List
Date: 
Message-ID: <21776@venera.isi.edu>
In article ... ········@athena.mit.edu (R. Whitney Winston) writes:

   I want to define a macro that will take an argument list similar to 
   the following:

   (defmacro macro-name (name arg0 arg1 &rest options)...)

   where the options are lists such as the following

   (:foo bar)
   (:foobar foobar)

   so options is ((:foo bar) (:foobar foobar)) however, I 
   want to use the keyword option to assign the values of
   foo and foobar.

   Here's a simplified version:
   (defmacro macro-name (name arg0 arg1 &rest options &key foo)....)

   would work for a macro call like

   (macro-name name arg0 arg1 :foo bar) 
   but I can't figure out how to make it work
   for something like

   (macro-name name arg0 arg1 (:foo bar))

   Any suggestions???

Well, if you would be satisfied with something that would look like 
   (macro-name name arg0 arg1 (:foo bar :foobar foobar))
that is, without separate sets of parentheses around each keyword
pair, it is easy  to arrange:
   (defmacro macro-name (name arg0 arg1 (&key foo foobar))...)

Otherwise, you will have to write your own keyword parser.  I don't
think you can coerce CommonLisp into parsing this construct yourself.
The closest you could come would be to bash the keyword argument pairs
together yourself and then invoke a second function (or macro) that
would do the parsing for you:

   (defmacro macro-name (name arg0 arg1 &rest options)
     `(macro-name-parser ,name ,arg0 ,arg1 ,@(reduce #'append options)))

   (defmacro macro-name-parser (name arg0 arg1 &key foo foobar) ...)

   Thanks...
   >>whitney
--

Thomas A. Russ                                             ···@isi.edu    
USC/ISI, 4676 Admiralty Way, Marina del Rey, CA 90292      (310) 822-1511