From: Douglas Philips
Subject: SETF and MACRO idiom  & archive wisdom...
Date: 
Message-ID: <3F4E13E6.9060704@mac.com>
After numbing myself searching through decades of c.l.l archives, I'm 
not sure if in my stupor I've just passed over what I'm looking for, or 
if the needle I want is on a completely different farm from the 
haystacks I was looking in.

Is there a way to write a SETF like thing, which does the evaluation of 
place only once, but which returns the _old_ value instead of the new? 
 From what I unearthed about SETF (DEFUN (SETF FOO)) (DEF-SETF....
PUSH isn't a SETy thing because it doesn't return the right thing, etc.
... that the answer is 'No'.

I would write a macro that wasn't SETFy, but I don't know how to avoid 
multiple evaluation:

(defmacro inc++ (x)
	`(prog1 ,x (incf ,x)))

that inc++ would be safe here (simple example):

(let ((src-index 0)
       (dest-index 0))
      ;...
      (while (some-test-of-validity src-index dest-index etc etc)
                 ; code which may skip/move src-index and/dest-index...
		(setf (aref dest-thing (inc++ dest-index))
		      (aref src-thing (inc++ src-index)))
                 ; code which may skip/move src-index and/dest-index...
		...))

inc++ wouldn't be safe with any side-effecting argument they way incf 
would safe.

So far I've taken to using the idiom:

(1- (incf ,incfy-thing))

Is there a better way/idiom? It seems a symbol macro of any variety (say 
analogous to 'with-slots' or 'with-accessors') has the multiple eval 
problem, just hidden a bit more.

Yes, I've poured over the HyperSpec on locations, but that hasn't sunk 
in yet (BTW: SETF is not like LOOP (IMHO), for those of you following 
another thread ;-) ;-) ).


If this has been answered in the archives, it hasn't been under anything 
I could find re: SETF and friends, so specific things or dates or people 
to search for would be very helpful.


Thanks,
	<D\'gou

From: Joe Marshall
Subject: Re: SETF and MACRO idiom  & archive wisdom...
Date: 
Message-ID: <y8xddeth.fsf@ccs.neu.edu>
Douglas Philips <····@mac.com> writes:

> After numbing myself searching through decades of c.l.l archives, I'm
> not sure if in my stupor I've just passed over what I'm looking for,
> or if the needle I want is on a completely different farm from the
> haystacks I was looking in.
>
> Is there a way to write a SETF like thing, which does the evaluation
> of place only once, but which returns the _old_ value instead of the
> new? From what I unearthed about SETF (DEFUN (SETF FOO)) (DEF-SETF....
> PUSH isn't a SETy thing because it doesn't return the right thing, etc.
> ... that the answer is 'No'.

Look at DEFINE-SETF-EXPANDER.
From: Nils Goesche
Subject: Re: SETF and MACRO idiom  & archive wisdom...
Date: 
Message-ID: <ly65khsuob.fsf@cartan.de>
Douglas Philips <····@mac.com> writes:

> I would write a macro that wasn't SETFy, but I don't know how to
> avoid multiple evaluation:
> 
> (defmacro inc++ (x)
> 	`(prog1 ,x (incf ,x)))

See

http://groups.google.com/groups?selm=lkd6stcsh3.fsf%40pc022.bln.elmeg.de

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Douglas Philips
Subject: Re: SETF and MACRO idiom  & archive wisdom...
Date: 
Message-ID: <3F4E23EC.1040906@mac.com>
Nils Goesche wrote:

> See
> 
> http://groups.google.com/groups?selm=lkd6stcsh3.fsf%40pc022.bln.elmeg.de
> 
> Regards,

Cool, thanks!

I have been over and over 5.1 and can't seem to find the example that 
you mention being broken. I did some examples that do the (cdr new) test 
that seems to be the difference in your two versions. Hmm..

I think what led me astray, was some notion that all this setf machinery 
was so that I could write things that would be useable in a setf 
expression. I think I got this notion from a mis-reading of:

5.1.1.2 Setf Expansions
...

Storing form

     a form which can reference both the temporary and the store 
variables, and which changes the value of the place and guarantees to 
return as its values the values of the store variables, which are the 
correct values for setf to return.


...


5.1.2 Kinds of Places

Several kinds of places are defined by Common Lisp; this section 
enumerates them. This set can be extended by implementations and by 
programmer code.



And somehow missed that I could use those forms for my own purposes.


Thanks again for the archive pointer!

<D\'gou
From: Nils Goesche
Subject: Re: SETF and MACRO idiom  & archive wisdom...
Date: 
Message-ID: <lyznhtrcs7.fsf@cartan.de>
Douglas Philips <····@mac.com> writes:

> Nils Goesche wrote:
> 
> > See
> > http://groups.google.com/groups?selm=lkd6stcsh3.fsf%40pc022.bln.elmeg.de
> 
> Cool, thanks!
> 
> I have been over and over 5.1 and can't seem to find the example
> that you mention being broken. I did some examples that do the (cdr
> new) test that seems to be the difference in your two
> versions. Hmm..

Look at the XPOP example in the dictionary entry for
GET-SETF-EXPANSION.  The (if (cdr new) (error ...)) test should be
done a couple lines higher :-)

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Kalle Olavi Niemitalo
Subject: Re: SETF and MACRO idiom  & archive wisdom...
Date: 
Message-ID: <877k4xajyl.fsf@Astalo.kon.iki.fi>
Douglas Philips <····@mac.com> writes:

> Is there a way to write a SETF like thing, which does the evaluation
> of place only once, but which returns the _old_ value instead of the
> new?

That sounds like SHIFTF, but only if the new value doesn't
depend on the old one.