From: Warren Lynn on
Hi,

Suppose I have this

(setf my-setf-func-name '(setf xyz))

How can I retrieve the function object for the function name stored in
my-setf-func-name?

(function my-setf-func-name)
does not work, as it won't evaluate my-setf-func-name as a variable.

(symbol-function my-setf-func-name)
complains (setf xyz) is not a symbol.

I hope I did not discover another "kink" in CL (have enough of it).
Please help. Thanks a lot.
PS: I am using SBCL.

From: Joshua Taylor on
On 2010.07.06 10:24 PM, Warren Lynn wrote:
> Hi,
>
> Suppose I have this
>
> (setf my-setf-func-name '(setf xyz))
>
> How can I retrieve the function object for the function name stored in
> my-setf-func-name?
>
> (function my-setf-func-name)
> does not work, as it won't evaluate my-setf-func-name as a variable.
>
> (symbol-function my-setf-func-name)
> complains (setf xyz) is not a symbol.
>
> I hope I did not discover another "kink" in CL (have enough of it).
> Please help. Thanks a lot.
> PS: I am using SBCL.
>

You can use FDEFINITION [1]:

> (defun (setf 1st) (value cons)
(setf (first cons) value))
(SETF 1ST)

> (fdefinition '(setf 1st))
#<interpreted function (SETF 1ST) 200DCFCA>

> (let ((my-setf-function-name '(setf 1st)))
(fdefinition my-setf-function-name))
#<interpreted function (SETF 1ST) 200DCFCA>

[1] http://www.lispworks.com/documentation/HyperSpec/Body/f_fdefin.htm
From: Peter Keller on
Warren Lynn <wrn.lynn(a)gmail.com> wrote:
> Hi,
>
> Suppose I have this
>
> (setf my-setf-func-name '(setf xyz))
>
> How can I retrieve the function object for the function name stored in
> my-setf-func-name?
>
> (function my-setf-func-name)
> does not work, as it won't evaluate my-setf-func-name as a variable.
>
> (symbol-function my-setf-func-name)
> complains (setf xyz) is not a symbol.
>
> I hope I did not discover another "kink" in CL (have enough of it).
> Please help. Thanks a lot.
> PS: I am using SBCL.

Hello,

I'm a bit new to Lisp, so I'll explain until I run out of correctness. :)

First: (setf my-setf-func-name '(setf xyz))

simply sets the place as denoted by the symbol my-setf-func-name to a literal
list containing two symbols 'setf' and 'xyz'. The list '(setf xyz) is not an
executable piece of code, or a symbol, or anything other than a literal list of
unbound symbols.

Second: setf is a macro, so getting the function of it won't do what you expect
(even if (function setf) returns a function) because the application of the
function with funcall evaluates all of the arguments:

Here is an example:

(funcall (function +) 1 2 3) => 6

(funcall (function setf) x 42) => error x is unbound

as opposed to

(setf x 42) => 42

Given your original expression, you never set any function name to anything,
you just made a symbol to evaluate to a list with two symbols in it.

Also, there is no such thing as (setf xyz) as an evaluable form since it has an
odd number of arguments.

Obviously, there is some other amount of context in which you think this is
the right thing to do, can you share with us what you are trying to do?

-pete
From: Peter Keller on
Peter Keller <psilord(a)cs.wisc.edu> wrote:
> Warren Lynn <wrn.lynn(a)gmail.com> wrote:
>> Hi,
>>
>> Suppose I have this
>>
>> (setf my-setf-func-name '(setf xyz))
>>
>> How can I retrieve the function object for the function name stored in
>> my-setf-func-name?
>>
>> (function my-setf-func-name)
>> does not work, as it won't evaluate my-setf-func-name as a variable.
>>
>> (symbol-function my-setf-func-name)
>> complains (setf xyz) is not a symbol.
>>
>> I hope I did not discover another "kink" in CL (have enough of it).
>> Please help. Thanks a lot.
>> PS: I am using SBCL.
>
> I'm a bit new to Lisp, so I'll explain until I run out of correctness. :)

Given Joshua's reply, I'm just going to shut up now. :/

-pete
From: Willem Broekema on
On Jul 7, 7:02 am, Joshua Taylor <tay...(a)cs.rpi.edu> wrote:
> You can use FDEFINITION [1]:
>
> > (defun (setf 1st) (value cons)
>     (setf (first cons) value))
> (SETF 1ST)
>
> > (fdefinition '(setf 1st))
>
> #<interpreted function (SETF 1ST) 200DCFCA>

And also #' takes setf functions:

#'(setf 1st) = #<interpreted function (SETF 1ST) 200DCFCA>

So instead of dealing with lists like '(setf 1st), consider passing
around the function object instead.

- Willem