hello, i have some code:
(defparameter rock (make-thing "rock"))
and i try to make a macro:
(defmacro create-thing (name)
`(defparameter ,name (make-thing \" ,name \")))
but something is wrong. how do i deal with quotation marks
in a defmacro?
thanks,
david
david wrote:
> hello, i have some code:
>
> (defparameter rock (make-thing "rock"))
>
> and i try to make a macro:
>
> (defmacro create-thing (name)
> `(defparameter ,name (make-thing \" ,name \")))
>
> but something is wrong. how do i deal with quotation marks
> in a defmacro?
As Pascal B. mentioned, you are not using the C pre-processor. Macros
are supposed to create a tree of Lisp objects suitable for consumption
by the compiler, not a stream of text.
Roughly, you probably want something like the following, which assumes
the NAME argument is a symbol, and then creates a string from that
symbol
(defmacro create-thing (name)
`(defparameter ,name (make-thing ,(symbol-name name))))
Testing...
(macroexpand-1 '(create-thing rock))
==>
(DEFPARAMETER ROCK (MAKE-THING "ROCK"))
··············@hotmail.com wrote:
> david wrote:
> > hello, i have some code:
> >
> > (defparameter rock (make-thing "rock"))
> >
> > and i try to make a macro:
> >
> > (defmacro create-thing (name)
> > `(defparameter ,name (make-thing \" ,name \")))
<snip>
> Roughly, you probably want something like the following, which assumes
> the NAME argument is a symbol, and then creates a string from that
> symbol
>
> (defmacro create-thing (name)
> `(defparameter ,name (make-thing ,(symbol-name name))))
Is it lispier to change the name to a string, or leave it as a symbol?
"Dvd Avins" <········@pobox.com> writes:
> Is it lispier to change the name to a string, or leave it as a symbol?
It depends whether it's used to be shown to the user,
or to be distinguished from other names internally.
--
__("< Marcin Kowalczyk
\__/ ······@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
"david" <·····@earthlink.net> writes:
> hello, i have some code:
>
> (defparameter rock (make-thing "rock"))
>
> and i try to make a macro:
>
> (defmacro create-thing (name)
> `(defparameter ,name (make-thing \" ,name \")))
>
> but something is wrong. how do i deal with quotation marks
> in a defmacro?
You're not in C anymore. Here, the source is s-expr: symbolic
expressions, not text. 'Concatenating' a " with a name and a "
doesn't mean anything.
What will name be bound to?
In these different cases:
(create-thing toto)
(create-thing "toto")
(create-thing #P"/tmp/toto")
(create-thing 2020)
(create-thing (intern "TOTO"))
(create-thing (+ 2000 20))
If you don't know, ask your lisp:
(defmacro create-thing (name)
(format t "~%value of name: ~S~%"type of name: ~S~%"
name (type-of name))
nil)
(create-thing toto)
(create-thing "toto")
(create-thing #P"/tmp/toto")
(create-thing 2020)
(create-thing (intern "TOTO"))
(create-thing (+ 2000 20))
Now, how do you get a string from:
- a symbol?
- a string?
- a character?
- a pathname?
- a number?
- a list?
- a form?
- ...
--
__Pascal Bourguignon__ http://www.informatimago.com/
"By filing this bug report you have challenged the honor of my
family. Prepare to die!"
"david" <·····@earthlink.net> writes:
> thanks, so far i have found symbol-name, princ-to-string, and
> pathname-name.
> i am stuck on the others.
>> Now, how do you get a string from:
>>
>> - a symbol?
>> - a string?
>> - a character?
STRING can handle these three.
>> - a pathname?
NAMESTRING
>> - a number?
>> - a list?
>> - a form?
These, and all the others actually can be handled by:
(format nil "~A" object)
--
__Pascal Bourguignon__ http://www.informatimago.com/
PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.