From: Gideon Kay
Subject: Passing function as argument
Date: 
Message-ID: <wsvD4.4614$OC2.123717@news2-win.server.ntlworld.com>
I am trying to pass a function name as an argument and am getting an error
regarding "global function".

The function is for example:

(defun is-also-true (m)
   (every #'its-true (produce-result-column #'m *three*)))

where m is a function name.

Any ideas?

Thanks

Gideon
··········@virgin.net
From: Pierre R. Mai
Subject: Re: Passing function as argument
Date: 
Message-ID: <87d7oh1g41.fsf@orion.dent.isdn.cs.tu-berlin.de>
"Gideon Kay" <···@virgin.net> writes:

> I am trying to pass a function name as an argument and am getting an error
> regarding "global function".
> 
> The function is for example:
> 
> (defun is-also-true (m)
>    (every #'its-true (produce-result-column #'m *three*)))
> 
> where m is a function name.

You are confused as to the use of #' or (function x).  It is used to
"convert" a name that is lexically or globally apparent into the
function value of that name.

You are just passing on the value of m (which might be the name of a
global function, or a (possibly lexical) function itself) that is
passed into your function.  So there is no need to "convert" again:

(defun is-also-true (m)
  (every #'its-true (produce-result-column m *three*)))

Then you can call is-also-true with either a symbol that denotes a
global function, or with a proper function, as usual:

(defun use-it ()
  (flet ((mypred (x) (> x 10)))
    (is-also-true 'evenp)
    (is-also-true #'evenp)
    (is-also-tue #'mypred)))

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]