From: Jeff
Subject: Setf macro macro
Date: 
Message-ID: <ozdrd.696136$8_6.490877@attbi_s04>
I'm trying to piece together a macro to define setf macros. As I have
quite a few of these that will all be (relatively) the same, give or
take a couple extra arguments. Here is the simple macro I have so far
(using LispWorks):

(defmacro defsetf-callback (callback &rest params)
  `(defsetf ,callback (,@params) (name)
     `(,callback ,,@params (make-pointer :symbol-name ,name))))

This is 95% correct:

(pprint (macroexpand-1 '(defsetf-callback my-callback x)))

=> (DEFSETF MY-CALLBACK (X) (NAME)
     `(,CALLBACK ,X (MAKE-POINTER :SYMBOL-NAME ,NAME)))

Everything is correct *except* for the ,CALLBACK -- I'd like it to read
MY-CALLBACK. I'm sure my woes are caused by the use of embedded
backquotes. Any suggestions?

Thanks,

Jeff M.

-- 
(a (href "http://www.retrobyte.org/"))
(a (href ···············@gmail.com"))

From: Chris Capel
Subject: Re: Setf macro macro
Date: 
Message-ID: <10qqq10clcel486@corp.supernews.com>
Jeff wrote:

> I'm trying to piece together a macro to define setf macros. As I have
> quite a few of these that will all be (relatively) the same, give or
> take a couple extra arguments. Here is the simple macro I have so far
> (using LispWorks):
> 
> (defmacro defsetf-callback (callback &rest params)
>   `(defsetf ,callback (,@params) (name)
>      `(,callback ,,@params (make-pointer :symbol-name ,name))))
> 
> This is 95% correct:
> 
> (pprint (macroexpand-1 '(defsetf-callback my-callback x)))
> 
> => (DEFSETF MY-CALLBACK (X) (NAME)
>      `(,CALLBACK ,X (MAKE-POINTER :SYMBOL-NAME ,NAME)))
> 
> Everything is correct *except* for the ,CALLBACK -- I'd like it to read
> MY-CALLBACK. I'm sure my woes are caused by the use of embedded
> backquotes. Any suggestions?

All these nested backquotes! First me, last night, then Peter today, and now
you!

OK, your problem is actually exactly like mine. Here's how to do it.

(defmacro defsetf-callback (callback &rest params)
  `(defsetf ,callback (,@params) (name)
     `(,',callback ,,@params (make-pointer :symbol-name ,name))))

I'm not sure exactly how it works. It seems like when you stick a quote in
there in the middle, the backquotes expand the commas in a different order
... or something.

Chris Capel
From: Antonio Menezes Leitao
Subject: Re: Setf macro macro
Date: 
Message-ID: <87oehemeaj.fsf@evaluator.pt>
Chris Capel <······@iba.nktech.net> writes:
> Jeff wrote:
>
>> I'm trying to piece together a macro to define setf macros. As I have
>> quite a few of these that will all be (relatively) the same, give or
>> take a couple extra arguments. Here is the simple macro I have so far
>> (using LispWorks):
>> 
>> (defmacro defsetf-callback (callback &rest params)
>>   `(defsetf ,callback (,@params) (name)
>>      `(,callback ,,@params (make-pointer :symbol-name ,name))))
>> 
>> This is 95% correct:
>> 
>> (pprint (macroexpand-1 '(defsetf-callback my-callback x)))
>> 
>> => (DEFSETF MY-CALLBACK (X) (NAME)
>>      `(,CALLBACK ,X (MAKE-POINTER :SYMBOL-NAME ,NAME)))
>> 
>> Everything is correct *except* for the ,CALLBACK -- I'd like it to read
>> MY-CALLBACK. I'm sure my woes are caused by the use of embedded
>> backquotes. Any suggestions?
>
> All these nested backquotes! First me, last night, then Peter today, and now
> you!
>
> OK, your problem is actually exactly like mine. Here's how to do it.
>
> (defmacro defsetf-callback (callback &rest params)
>   `(defsetf ,callback (,@params) (name)
>      `(,',callback ,,@params (make-pointer :symbol-name ,name))))
>
> I'm not sure exactly how it works. It seems like when you stick a quote in
> there in the middle, the backquotes expand the commas in a different order
> ... or something.
>

Doubly nested backquotes are hard to understand and what I usually do
is to follow the rules presented by Steele in CLTL:

,,p means ``the value of p is a form; use the value of the value of p.''

,,@q means ``the value of q is a list of forms; splice the list of
values of the elements of the value of q.''

,',r means ``the value of r may be any object; use the value of r that
is available at the time of first evaluation, that is, when the outer
backquote is evaluated.'' (To use the value of r that is available at
the time of second evaluation, that is, when the inner backquote is
evaluated, just use ,r.)

,',@s means ``the value of s must be a singleton list of any object;
use the element of the value of s that is available at the time of
first evaluation, that is, when the outer backquote is evaluated.''
Note that s must be a singleton list because it will be spliced into a
form (quote ), and the quote special form requires exactly one subform
to appear; this is generally true of the sequence ',@. (To use the
value of s that is available at the time of second evaluation, that
is, when the inner backquote is evaluated, just use ,@s,in which case
the list s is not restricted to be singleton, or ,(car s).)

,@,p means ``the value of p is a form; splice in the value of the
value of p.''

,@,@q means ``the value of q is a list of forms; splice each of the
values of the elements of the value of q, so that many splicings
occur.''

,@',r means ``the value of r must be a list; splice in the value of r
that is available at the time of first evaluation, that is, when the
outer backquote is evaluated.'' (To splice the value of r that is
available at the time of second evaluation, that is, when the inner
backquote is evaluated, just use ,@r.)

,@',@s means ``the value of s must be a singleton list whose element
is a list; splice in the list that is the element of the value of s
that is available at the time of first evaluation, that is, when the
outer backquote is evaluated.'' (To splice the element of the value of
s that is available at the time of second evaluation, that is, when
the inner backquote is evaluated, just use ,@(car s).)

Ant�nio Leit�o.
From: Jeff
Subject: Re: Setf macro macro
Date: 
Message-ID: <Lhtrd.187698$R05.112825@attbi_s53>
Chris Capel wrote:

> All these nested backquotes! First me, last night, then Peter today,
> and now you!

Haha! I was just noticing Peter's post just now. I had the same
reaction.

> OK, your problem is actually exactly like mine. Here's how to do it.
> 
> [snipped]
> 
> I'm not sure exactly how it works. It seems like when you stick a
> quote in there in the middle, the backquotes expand the commas in a
> different order ... or something.

How wierd. I'll have to look at it more closely when I have time...
right now it's time to fix it and go to bed! Thanks!

Jeff M.

-- 
(a (href "http://www.retrobyte.org/"))
(a (href ···············@gmail.com"))
From: Jeff
Subject: Re: Setf macro macro
Date: 
Message-ID: <sDdrd.173624$HA.110495@attbi_s01>
Jeff wrote:

> I'm trying to piece together a macro to define setf macros. As I have
> quite a few of these that will all be (relatively) the same, give or
> take a couple extra arguments. Here is the simple macro I have so far
> (using LispWorks):
> 
> (defmacro defsetf-callback (callback &rest params)
>   `(defsetf ,callback (,@params) (name)
>      `(,callback ,,@params (make-pointer :symbol-name ,name))))
> 
> This is 95% correct:
> 
> (pprint (macroexpand-1 '(defsetf-callback my-callback x)))
> 
> => (DEFSETF MY-CALLBACK (X) (NAME)
>      `(,CALLBACK ,X (MAKE-POINTER :SYMBOL-NAME ,NAME)))
> 

I should add that changing ,callback to ,,callback does this:

 => (DEFSETF MY-CALLBACK (X) (NAME)
      `(,MY-CALLBACK ,X (MAKE-POINTER :SYMBOL-NAME ,NAME)))

Which is close, but need to rid myself of a comma.

-- 
(a (href "http://www.retrobyte.org/"))
(a (href ···············@gmail.com"))