From: Marc Battyani
Subject: (setf <name>) function designator
Date: 
Message-ID: <AFE3B7E41B41FFB9.65A71C4E76CC1087.81C28D2B1A8EB289@lp.airnews.net>
How can I dynamically create the equivalent of (function (setf  <name>))
where <name> is a symbol?

149 > (function (setf slot))
#<standard-generic-function (setf slot) 21953B84>

150 > (function (list 'setf 'slot))

Error: Syntactic error in form (function (list (quote setf) (quote slot))):
   Illegal function name (list (quote setf) (quote slot)).
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

In fact I want to be able to do this (which does not work)

(defun funcall-setf (symbol object value)
    (funcall (list 'setf symbol) value object))

Thanks,

Marc

From: Kent M Pitman
Subject: Re: (setf <name>) function designator
Date: 
Message-ID: <sfwu1yqye1h.fsf@world.std.com>
"Marc Battyani" <·············@fractalconcept.com> writes:

> How can I dynamically create the equivalent of (function (setf  <name>))
> where <name> is a symbol?
> 
> 149 > (function (setf slot))
> #<standard-generic-function (setf slot) 21953B84>
> 
> 150 > (function (list 'setf 'slot))
> 
> Error: Syntactic error in form (function (list (quote setf) (quote slot))):
>    Illegal function name (list (quote setf) (quote slot)).
>   1 (abort) Return to level 0.
>   2 Return to top loop level 0.
> 
> In fact I want to be able to do this (which does not work)
> 
> (defun funcall-setf (symbol object value)
>     (funcall (list 'setf symbol) value object))

(funcall (fdefinition `(setf ,symbol)) value object)

Note, however, that SETF's are not required to take just one argument.

 (defvar *foo*)
 (defun foo () *foo*)
 (defun (setf foo) (new-value) (setq *foo* new-value))

Some other setters take more args.

 (defvar *contents* (make-array '(5 5)))
 (defun contents (x y) (aref *contents* x y))
 (defun (setf contents) (new-contents x y) 
   (setf (aref *contents* x y) new-contents))
 (setf (contents 3 3) 'foo)

You'd do better with something like this:

(defun funcall-setf (symbol new-value &rest args)
  (apply (fdefinition (setf ,symbol)) new-value args))
From: Marc Battyani
Subject: Re: (setf <name>) function designator
Date: 
Message-ID: <38703B790EC724A6.E28F0DE2F39B2EF6.243B9743DB801CAC@lp.airnews.net>
"Kent M Pitman" <······@world.std.com> wrote
> "Marc Battyani" <·············@fractalconcept.com> writes:
>
> > How can I dynamically create the equivalent of (function (setf  <name>))
> > where <name> is a symbol?
> >
> > 149 > (function (setf slot))
> > #<standard-generic-function (setf slot) 21953B84>
> >
> > 150 > (function (list 'setf 'slot))
> >
> > Error: Syntactic error in form (function (list (quote setf) (quote
slot))):
> >    Illegal function name (list (quote setf) (quote slot)).
> >   1 (abort) Return to level 0.
> >   2 Return to top loop level 0.
> >
> > In fact I want to be able to do this (which does not work)
> >
> > (defun funcall-setf (symbol object value)
> >     (funcall (list 'setf symbol) value object))
>
> (funcall (fdefinition `(setf ,symbol)) value object)
>
> Note, however, that SETF's are not required to take just one argument.
>
>  (defvar *foo*)
>  (defun foo () *foo*)
>  (defun (setf foo) (new-value) (setq *foo* new-value))
>
> Some other setters take more args.
>
>  (defvar *contents* (make-array '(5 5)))
>  (defun contents (x y) (aref *contents* x y))
>  (defun (setf contents) (new-contents x y)
>    (setf (aref *contents* x y) new-contents))
>  (setf (contents 3 3) 'foo)
>
> You'd do better with something like this:
>
> (defun funcall-setf (symbol new-value &rest args)
>   (apply (fdefinition (setf ,symbol)) new-value args))

It was only an example, in fact I wanted to call CLOS slot accessors but
couldn't put a name on FDEFINITION.

Thanks,

Marc
From: Frode Vatvedt Fjeld
Subject: Re: (setf <name>) function designator
Date: 
Message-ID: <2hwv3mdccj.fsf@dslab7.cs.uit.no>
"Marc Battyani" <·············@fractalconcept.com> writes:

> In fact I want to be able to do this (which does not work)
> 
> (defun funcall-setf (symbol object value)
>     (funcall (list 'setf symbol) value object))

How about:

  (defun funcall-setf (symbol object value)
    (funcall (fdefinition (list 'setf symbol)) value object))

FDEFINITION is the functional accessor to the function-name namespace,
whereas FUNCTION (as in #') is a special operator that does
compile-time "stuff".

-- 
Frode Vatvedt Fjeld
From: Steven M. Haflich
Subject: Re: (setf <name>) function designator
Date: 
Message-ID: <3B8D2862.583CE6D@pacbell.net>
Frode Vatvedt Fjeld wrote:
> 
> "Marc Battyani" <·············@fractalconcept.com> writes:
> 
> > In fact I want to be able to do this (which does not work)
> >
> > (defun funcall-setf (symbol object value)
> >     (funcall (list 'setf symbol) value object))
> 
> How about:
> 
>   (defun funcall-setf (symbol object value)
>     (funcall (fdefinition (list 'setf symbol)) value object))
> 
> FDEFINITION is the functional accessor to the function-name namespace,
> whereas FUNCTION (as in #') is a special operator that does
> compile-time "stuff".

Frode's answer points in the right direction, but that invocation of
magical "compile-time `stuff'" suggests that the answer is, well,
lacking some precision (:-).

Here's the simple distinction between fdefinition and function (ignoring
the special case where function is given a lambda-expression subform):

FDEFINITION is a regular function that evaluates its single argument at
exec time.  It does lookup in the global function name namespace.  It is
setfable.

FUNCTION is indeed a special form that does _not_ evaluate its single
subform.  It does lookup in the lexical function name namespace, i.e.,
it is sensitive to flet/labels bindings, with the usual semantics where
the global namespace is wrapped outside any lexical bindings.  To put it
yet another way, the FUNCTION special form does exec-time lookup with
exactly the same semantics as regular lisp fnuction call form resolves a
function name in the car of a form.  FUNCTION is not setfable.

While efficient compilation implies that the compiler must do some "stuff"
at compile time when it sees a FUNCTION form, there is nothing in the
semantics of FUNCTION that has any special reliance on compilation.  In
an implementation that has an interpreter (that does not depend on
compilation) FUNCTION works with the same semantics as in compiled code,
and does not need to depend on the compiler in any way.
From: Marc Battyani
Subject: Re: (setf <name>) function designator
Date: 
Message-ID: <74A4791C165B4E7C.5D91624DE0E3F959.BF2CA59D59717277@lp.airnews.net>
"Steven M. Haflich" <·······@pacbell.net> wrote
>
> Frode Vatvedt Fjeld wrote:
> >
> > "Marc Battyani" <·············@fractalconcept.com> writes:
> >
> > > In fact I want to be able to do this (which does not work)
> > >
> > > (defun funcall-setf (symbol object value)
> > >     (funcall (list 'setf symbol) value object))
> >
> > How about:
> >
> >   (defun funcall-setf (symbol object value)
> >     (funcall (fdefinition (list 'setf symbol)) value object))
> >
> > FDEFINITION is the functional accessor to the function-name namespace,
> > whereas FUNCTION (as in #') is a special operator that does
> > compile-time "stuff".
>
> Frode's answer points in the right direction, but that invocation of
> magical "compile-time `stuff'" suggests that the answer is, well,
> lacking some precision (:-).
>
> Here's the simple distinction between fdefinition and function (ignoring
> the special case where function is given a lambda-expression subform):
>
> FDEFINITION is a regular function that evaluates its single argument at
> exec time.  It does lookup in the global function name namespace.  It is
> setfable.
>
> FUNCTION is indeed a special form that does _not_ evaluate its single
> subform.  It does lookup in the lexical function name namespace, i.e.,
> it is sensitive to flet/labels bindings, with the usual semantics where
> the global namespace is wrapped outside any lexical bindings.  To put it
> yet another way, the FUNCTION special form does exec-time lookup with
> exactly the same semantics as regular lisp fnuction call form resolves a
> function name in the car of a form.  FUNCTION is not setfable.
>
> While efficient compilation implies that the compiler must do some "stuff"
> at compile time when it sees a FUNCTION form, there is nothing in the
> semantics of FUNCTION that has any special reliance on compilation.  In
> an implementation that has an interpreter (that does not depend on
> compilation) FUNCTION works with the same semantics as in compiled code,
> and does not need to depend on the compiler in any way.

Thanks for the clarification. In fact my problem was more with FUNCALL that
is accepting a symbol but not a list (setf symbol)
A quick glance at my sources found that every time I used FDEFINITION it was
for exactly this case of funcalling a setf fonction.

Marc
From: Marc Battyani
Subject: Re: (setf <name>) function designator
Date: 
Message-ID: <7AE8CCB4BB63533E.5938B6A1AF3BBAB8.C67764F6ECEB16BF@lp.airnews.net>
"Frode Vatvedt Fjeld" <······@acm.org> wrote
> "Marc Battyani" <·············@fractalconcept.com> writes:
>
> > In fact I want to be able to do this (which does not work)
> >
> > (defun funcall-setf (symbol object value)
> >     (funcall (list 'setf symbol) value object))
>
> How about:
>
>   (defun funcall-setf (symbol object value)
>     (funcall (fdefinition (list 'setf symbol)) value object))
>
> FDEFINITION is the functional accessor to the function-name namespace,
> whereas FUNCTION (as in #') is a special operator that does
> compile-time "stuff".

It's exactly what I was looking for, I couldn't put a name on it today.

Thanks,

Marc