From: Peter Keller on
Hello,

Is it possible to have a macro generate a keyword?

As in

(defmacro foo (thing)
`(list :,thing))

Obviously, that doesn't work. I need this because the keyword is being
defined in a package via a macro and I'd like it to be available to the
users of the package.

Thanks.

-pete
From: Rob Warnock on
Peter Keller <psilord(a)merlin.cs.wisc.edu> wrote:
+---------------
| Is it possible to have a macro generate a keyword?
+---------------

Sure.

+---------------
| As in
| (defmacro foo (thing)
| `(list :,thing))
|
| Obviously, that doesn't work. I need this because the keyword is being
| defined in a package via a macro and I'd like it to be available to the
| users of the package.
+---------------

How about this?

> (defmacro foo (thing)
`(list ,(intern (string thing) :keyword)))

FOO
> (foo bar)

(:BAR)
>


-Rob

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

From: Peter Keller on
Rob Warnock <rpw3(a)rpw3.org> wrote:
> Peter Keller <psilord(a)merlin.cs.wisc.edu> wrote:
> +---------------
> | As in
> | (defmacro foo (thing)
> | `(list :,thing))
> |
> | Obviously, that doesn't work. I need this because the keyword is being
> | defined in a package via a macro and I'd like it to be available to the
> | users of the package.
> +---------------
>
> How about this?
>
> > (defmacro foo (thing)
> `(list ,(intern (string thing) :keyword)))
>
> FOO
> > (foo bar)
>
> (:BAR)
> >

Ooh! That looks perfect! Thank you!

-pete