Subject: Re: &optional with &key
From: (Rob Warnock)
Date: Tue, 10 Dec 2002 05:40:03 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
Adam Warner <> wrote:
| Before I knew about &key I was using &rest to parse keyword parameters.
| I could parse a URI in these three forms:
|    1. (a :href "uri")
|    2. (a :href "uri" "description")
|    3. (a "description" :href "uri")
| This doesn't work...
|    (defun a (&optional desc &key href) (write desc) (write href))
| I'd like to know how far I can go to provide such variation in input
| without having to resort to using &rest and then parsing the resulting
| list myself.

If you can make one massive search & replace edit over your corpus
and replace all occurences of #2 & #3 with the following alternatives,
life might become a lot simpler for you:

     2'. (a :href "uri" :text "description")
     3'. (a :text "description" :href "uri")


p.s. I replied only because I've been using Tim Bradshaw's HTOUT macro
a lot recently, and he similarly finesses the inverse problem -- what to
do about an HTML attribute that has no value. His solution: Force the Lisp
keyword to be provided an explicit value of NIL in that case, e.g.:

     ((:ul :compact nil)	; outputs <UL COMPACT>
       :li "First item."
       :li "Second item.")

p.p.s. In HTOUT, one writes #2 as:

     ((:a :href "uri") "description")

which is yet another solution that works.

Rob Warnock, PP-ASEL-IA		<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607