From: david
Subject: defmacro syntax
Date: 
Message-ID: <1148231775.701664.313460@i39g2000cwa.googlegroups.com>
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

From: ··············@hotmail.com
Subject: Re: defmacro syntax
Date: 
Message-ID: <1148233321.306139.320030@j33g2000cwa.googlegroups.com>
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"))
From: david
Subject: Re: defmacro syntax
Date: 
Message-ID: <1148240765.811150.266700@i40g2000cwc.googlegroups.com>
that is exactly what i wanted, thanks.
From: Dvd Avins
Subject: Re: defmacro syntax
Date: 
Message-ID: <1148246502.919229.8120@i40g2000cwc.googlegroups.com>
··············@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?
From: Marcin 'Qrczak' Kowalczyk
Subject: Re: defmacro syntax
Date: 
Message-ID: <87r72nxdc9.fsf@qrnik.zagroda>
"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/
From: Pascal Bourguignon
Subject: Re: defmacro syntax
Date: 
Message-ID: <87wtcf9tco.fsf@thalassa.informatimago.com>
"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!"
From: david
Subject: Re: defmacro syntax
Date: 
Message-ID: <1148240693.037176.154390@g10g2000cwb.googlegroups.com>
thanks, so far i have found symbol-name, princ-to-string, and
pathname-name.
i am stuck on the others.
From: Pascal Bourguignon
Subject: Re: defmacro syntax
Date: 
Message-ID: <87irnyan9p.fsf@thalassa.informatimago.com>
"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.