[pro] [Q] introspecting setf expanders

Martin Simmons martin at lispworks.com
Tue Oct 9 11:29:27 UTC 2012


>>>>> On Mon, 08 Oct 2012 17:38:42 +0200, Didier Verna said:
> 
> Pascal Costanza wrote:
> 
> > Just guessing: If you see that the writer form is a funcall to a setf
> > function, you can then check with fboundp if such a function actually
> > exists. This is probably a bit shaky, but maybe good enough for
> > practical purposes?
> 
>   Good idea. To be more precise:
> 
> - if the writer form is something else than (FUNCALL #'(SETF FOO) ...)
>   then there is a defsetf going on (it even takes precedence over a
>   potential setf function).
> 
> - if the writer form is (FUNCALL #'(SETF FOO) ...) and that function is
>   bound, then there is a setf function going on but no defsetf.
> 
> - otherwise, there is no writer at all.
> 
> 
> I think this might just work.

As Pascal said, it's a bit shaky.  E.g. a user could define

(defsetf foo (x) (y)
  `(funcall #'(setf foo) ,y ,x))

which gives a false negative.

Also, it won't be portable, because the (FUNCALL #'(SETF FOO) ...) form isn't
required (the standard just specifies something with the same effect as it).

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/




More information about the pro mailing list