From: tebeka michael
Subject: Help - Functions as arguments
Date: 
Message-ID: <5q2sar$g7t@news.huji.ac.il>
Hello All.

I've done:
(defun foo(func) 
       (progn (princ 'x) 
              (setf (funcall func x) 'zzz)))

Where x is a sturcture and func is on of the access function of this
structure

Got the answer:
On Allegro:
Error: Setf of apply is only defined for function args of form #'symbol.
  [condition type: PROGRAM-ERROR]

On Clisp:
*** - SETF FUNCALL is only defined for functions of the form #'symbol.

Any idea how to go around this one?

Thanks.

--
     O O      Smile, damn it, smile.
    \___/    
                      Miki
               ······@cs.bgu.ac.il	
         http://www.cs.bgu.ac.il/~tebeka

-- Ambition is a poor excuse for not having enough sense to be lazy --



      

From: Barry Margolin
Subject: Re: Help - Functions as arguments
Date: 
Message-ID: <5q2uka$efu@tools.bbnplanet.com>
In article <··········@news.huji.ac.il>, tebeka michael <······@black> wrote:
>*** - SETF FUNCALL is only defined for functions of the form #'symbol.
>
>Any idea how to go around this one?

Have the caller pass the setting function instead of the getting function
as an argument.  The problem is that there's no way for SETF to know what
the corresponding setting function is by itself.

-- 
Barry Margolin, ······@bbnplanet.com
BBN Corporation, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
From: Mark McConnell
Subject: Re: Help - Functions as arguments
Date: 
Message-ID: <33C598B7.354D@math.okstate.edu>
tebeka michael wrote:
> 
> Hello All.
> 
> I've done:
> (defun foo(func)
>        (progn (princ 'x)
>               (setf (funcall func x) 'zzz)))
> 
> Where x is a sturcture and func is on of the access function of this
> structure

Try this:

(defmacro foo (func)
  `(progn
     (princ 'x)
     (setf (,func x) 'zzz)))

If x is an instance of the structure ship, and one of the slots
of a ship is (ship-y ...), then

(foo ship-y)

will be expanded into

(progn
  (princ 'x)
  (setf (ship-y x) 'zzz))

Because this is a macro, you don't have to pass in a `function
version' of ship-y, or use funcalls.  You are merely passing in the
_name_ of the function you want to use.

I am so glad I read Paul Graham's _On Lisp_!  People on this
group said it was good, but I never knew how much.  I find my
mind very subtly expanded.