From: Jimka
Subject: Undefined function (SETF FUNCALL)
Date: 
Message-ID: <1122753011.422376.101850@z14g2000cwz.googlegroups.com>
Can someone suggest a way to avoid this compiler error?

I'd like to refactor the following dual WHEN expressions
which only differ by swapping RIGHT and LEFT everywhere they
occur.

      (when (member (name left) (left-instances ic) :test #'eq)
	(push (name left) (right-instances ic))
	(setf (left-instances ic)
	      (delete (name left) (left-instances ic) :test #'eq)))

      (when (member (name right) (right-instances ic) :test #'eq)
	(push (name right) (left-instances ic))
	(setf (right-instances ic)
	      (delete (name right) (right-instances ic) :test #'eq)))

I've changed the forms to the following:

      (swap-connected-instances ic left  #'left-instances
#'right-instances)
      (swap-connected-instances ic right #'right-instances
#'left-instances)

And i've written the function:

(defun swap-connected-instances (ic left left-fun right-fun)
  (when (member (name left) (funcall left-fun ic) :test #'eq)
    (push (name left) (funcall right-fun ic))
    (setf (funcall left-fun ic)
	  (delete (name left) (funcall left-fun ic) :test #'eq))))

However, the problem is that (SETF (FUNCALL ...)) causes a compiler
error.  :-(
     Undefined function (SETF FUNCALL) as the argument to FUNCTION

Does this mean the only way to refactor this is by using a macro
instead of a function?

I'd like to make it a function because i'm
profiling these functions seperate from the function calling them.
  

-jim

From: Edi Weitz
Subject: Re: Undefined function (SETF FUNCALL)
Date: 
Message-ID: <uvf2sm4lg.fsf@agharta.de>
On 30 Jul 2005 12:50:11 -0700, "Jimka" <·····@rdrop.com> wrote:

> Does this mean the only way to refactor this is by using a macro
> instead of a function?

Depends on how (SETF LEFT-INSTANCE) is defined.  If it's a function
defined with

  (defun (setf left-instance) (...)
     ...)

then #'(SETF LEFT-INSTANCE) is a functional object you can use as an
argument to your function and call with FUNCALL or APPLY.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Arthur Lemmens
Subject: Re: Undefined function (SETF FUNCALL)
Date: 
Message-ID: <opsuqtm5iok6vmsw@news.xs4all.nl>
Edi Weitz wrote:

> On 30 Jul 2005 12:50:11 -0700, "Jimka" <·····@rdrop.com> wrote:
>
>> Does this mean the only way to refactor this is by using a macro
>> instead of a function?
>
> Depends on how (SETF LEFT-INSTANCE) is defined.  If it's a function
> defined with
>
> (defun (setf left-instance) (...)
> ...)
>
> then #'(SETF LEFT-INSTANCE) is a functional object you can use as an
> argument to your function and call with FUNCALL or APPLY.

In Jim's example, that means he would have to pass the reader function
and the writer function separately.  So instead of

  (defun swap-connected-instances (ic left left-fun right-fun)

you'd get something like:

  (defun swap-connected-instances (ic left left-reader left-writer
                                      right-reader right-writer)
From: Edi Weitz
Subject: Re: Undefined function (SETF FUNCALL)
Date: 
Message-ID: <ufytwm3tg.fsf@agharta.de>
On Sat, 30 Jul 2005 22:24:31 +0200, Arthur Lemmens <········@xs4all.nl> wrote:

> In Jim's example, that means he would have to pass the reader
> function and the writer function separately.  So instead of
>
>   (defun swap-connected-instances (ic left left-fun right-fun)
>
> you'd get something like:
>
>   (defun swap-connected-instances (ic left left-reader left-writer
>                                       right-reader right-writer)

Sure.  I forgot to mention that.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")