From: Spandan Choudury
Subject: Re: How use a standard (existing) function as argument to a new one?
Date: 
Message-ID: <1992Jun1.174515.25346@ucunix.san.uc.edu>
In Art. 2763 Barry Margolin writes....

>In article <······················@ucunix.san.uc.edu> ········@ucunix.san.uc.edu (Spandan Choudury) writes:
>>How can I define a function of the type  " test-func (func list) " so
>>calls like "(test-func car '(1 2 3 4))" , "(test-func cdr '(1 2 3 4))",
>>etc.. may be made..(to obtain the actual "car", "cdr", etc.. respectively,
>>of the 2nd argument (list)) ?
...

>(defun test-fun (func list)
>  (funcall func list))
>
>(test-func #'car '(1 2 3 4)) -> 1
>(test-func #'cdr '(1 2 3 4)) -> (2 3 4)
>
>Note that in CL, you must use #'<name> to refer to the functional
>interpretation of <name>.  Just saying <name> refers to it as a normal
>variable.
>

Well, thanks for your post, but I *was* actually looking for making function 
calls *without* having to use the #' (as indicated in my earlier post), as 
opposed to what is ordinarily always done (in CL). (I was wondering if there 
was a way of bypassing that automatic variable interpretation...).

             --Spandan.

From: Joe Konstan
Subject: Re: How use a standard (existing) function as argument to a new one?
Date: 
Message-ID: <10e6d5INNm7h@agate.berkeley.edu>
Spandan Choudury wanted to write a test-func that could be called as:
	(test-func car '(1 2 3 4)) ==> 1

Barry Margolin responds with a call to funcall that forces it to be
called as:
	(test-func #'car '(1 2 3 4))

Spandan Choudury however *really* wants to avoid the #'

So...

	When all else fails, call MACRO-MAN!
		Speed of Lisp
		Power of Metaevaluation
		Promise of Obscurity (well, not always)

What you seem to want is:

	(defmacro test-func (func list)
          `(funcall #',func ,list))

The drawback is that this is not a function (and for instance cannot be
passed to mapcar, apply, etc.).  If that was your goal, then no, there is no 
way to define a *true function* that takes a symbol (unquoted) as a parameter
and  refrains from evaluating it.

Joe Konstan
From: Barry Margolin
Subject: Re: How use a standard (existing) function as argument to a new one?
Date: 
Message-ID: <10eerkINNn4i@early-bird.think.com>
In article <·····················@ucunix.san.uc.edu> ········@ucunix.san.uc.edu (Spandan Choudury) writes:
>In Art. 2763 Barry Margolin writes....

You shouldn't refer to articles by their article number, as that is purely
local to your system.  You should use the Message-ID.

>>In article <······················@ucunix.san.uc.edu> ········@ucunix.san.uc.edu (Spandan Choudury) writes:
>>>How can I define a function of the type  " test-func (func list) " so
>>>calls like "(test-func car '(1 2 3 4))" , "(test-func cdr '(1 2 3 4))",
>>>etc.. may be made..(to obtain the actual "car", "cdr", etc.. respectively,
>>>of the 2nd argument (list)) ?

>>Note that in CL, you must use #'<name> to refer to the functional
>>interpretation of <name>.  Just saying <name> refers to it as a normal
>>variable.

>Well, thanks for your post, but I *was* actually looking for making function 
>calls *without* having to use the #' (as indicated in my earlier post), as 
>opposed to what is ordinarily always done (in CL). (I was wondering if there 
>was a way of bypassing that automatic variable interpretation...).

If TEST-FUNC is a function, then there's no way to prevent the normal
evaluation of the arguments.  They are evaluated and then the function is
invoked.

You could define TEST-FUNC as a macro.  Macros receive all the original
arguments uninterpreted, and rewrite the call as they want:

(defmacro test-func (func list)
  `(funcall #',func ,list))

(macroexpand '(test-func car '(1 2 3 4)))
  => (funcall #'car '(1 2 3 4))

But note that macros have their own limitations.  They need to be defined
before the callers, they have to be loaded at compile time if they're
used in files other than the one they are defined in, they can't be passed
around as arguments, and the callers need to be recompiled to pick up
changed definitions.

Why do you need to do this?
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar
From: John Gateley
Subject: Re: How use a standard (existing) function as argument to a new one?
Date: 
Message-ID: <GATELEY.92Jun2165832@tone.rice.edu>
In article <·····················@ucunix.san.uc.edu> ········@ucunix.san.uc.edu (Spandan Choudury) writes:

   Well, thanks for your post, but I *was* actually looking for making function 
   calls *without* having to use the #' (as indicated in my earlier post), as 
   opposed to what is ordinarily always done (in CL). (I was wondering if there 
   was a way of bypassing that automatic variable interpretation...).

Well, its a complete hack, but you can do:

(setq car #'car)

etc.

j
--
·······@rice.edu
Si pots llegir aquest, m'agradaria si contestessis.