I would like to build the form
(foo :initarg :foo)
using something along the lines of
(let ((slot-name 'foo))
`(,slot-name :initarg :,slot-name))
(which does not work).
Is there a way of doing it without messing around with intern ?
From: Christopher C. Stacy
Subject: Re: Building keywords within backquote
Date:
Message-ID: <ud6l38lau.fsf@dtpq.com>
>>>>> On 07 Mar 2003 11:18:34 +0100, Jacek Generowicz ("Jacek") writes:
Jacek> I would like to build the form
Jacek> (foo :initarg :foo)
Jacek> using something along the lines of
Jacek> (let ((slot-name 'foo))
Jacek> `(,slot-name :initarg :,slot-name))
Jacek> (which does not work).
Sure, because macros don't manipulate strings; they manipulate code.
Jacek> Is there a way of doing it without messing around with intern ?
In order to create a new symbol, you'll need to call some function
that creates symbols (eg. INTERN). But why are you reluctant to
call INTERN? You'll want to use the KEYWORD package, you know.
Use SYMBOL-NAME to get the name of the symbol.
Jacek Generowicz <················@cern.ch> writes:
> (let ((slot-name 'foo))
> `(,slot-name :initarg :,slot-name))
>
> (which does not work).
>
> Is there a way of doing it without messing around with intern ?
This is almost like asking how you can bake blueberry pie without
messing around with blueberries.. The answer is "no, why would you
want that?"
(let ((slot-name 'foo))
`(,slot-name :initarg ,(intern (symbol-name slot-name) :keyword)))
--
Frode Vatvedt Fjeld
Frode Vatvedt Fjeld <······@cs.uit.no> writes:
> "no, why would you want that?"
······@dtpq.com (Christopher C. Stacy) writes:
> But why are you reluctant to call INTERN?
Just wondering whether I was missing something.
Yes, it's clear now that I am making a _new_ symbol, which is the job
of INTERN, not of backquote.
Thanks for your answers.
Jacek Generowicz <················@cern.ch> wrote in message news:<···············@pcepsft001.cern.ch>...
> Frode Vatvedt Fjeld <······@cs.uit.no> writes:
>
> > "no, why would you want that?"
>
> ······@dtpq.com (Christopher C. Stacy) writes:
>
> > But why are you reluctant to call INTERN?
>
>
> Just wondering whether I was missing something.
>
> Yes, it's clear now that I am making a _new_ symbol, which is the job
> of INTERN, not of backquote.
Right so in other words, this:
(let ((slot-name 'foo))
`(,slot-name :initarg :,slot-name))
becomes this:
(let* ((slot-name 'foo)
(slot-name-keyword (intern (symbol-name slot-name) "KEYWORD")))
`(,slot-name :initarg ,slot-name-keyword))
==> (FOO :INITARG :FOO)