From: Dragos-Anton Manolescu
Subject: Q: passing parameters
Date: 
Message-ID: <DRAGOS.95Oct5205929@sweetbay.will.uiuc.edu>
Hi,

I was wondering if there is possible to supply (constant) data to any
of the mapping functions (e.g. mapcar, remove-if, etc.) without
relying to global variables.

I'm oversimplifying here; suppose:

(remove-if #'test-function a-list)

and (defun test-function (an-element)
     (equal an-element A-PARAMETER))
                       ^^^^^^^^^^^
Is there any way to do this without a global variable?


Please reply by e-mail if possible.

Thanx!
-- 
Dragos Manolescu                              WILL AM/FM/TV
                                              1110 W. Main Street
e-mail: ········@uiuc.edu                     Urbana, IL 61801
                                              Phone: (217)333-1070

From: Ralf Muschall
Subject: Re: Q: passing parameters
Date: 
Message-ID: <454am6$j10@fsuj01.rz.uni-jena.de>
In article <···················@sweetbay.will.uiuc.edu> Dragos Manolescu <········@uiuc.edu> writes:

>I was wondering if there is possible to supply (constant) data to any
>of the mapping functions (e.g. mapcar, remove-if, etc.) without
>relying to global variables.

>I'm oversimplifying here; suppose:

>(remove-if #'test-function a-list)

>and (defun test-function (an-element)
>     (equal an-element A-PARAMETER))
>                       ^^^^^^^^^^^

If you don't want to use a global variable, you either
have to enter its value as a constant (e.g. a literal 6
instead of A-PARAMETER), or pass it as an argument to the
function which uses test-function.

E.g.

(defun flcmp (fu conval lst)
    (funcall fu #'(lambda (x) (equal x conval)) lst))

which would then be called as in

(flcmp #'mapcar 6 '(1 3 5 6 8 9))

returning (nil nil nil t nil nil)

You also might say

(let ((A-PARAMETER 6))
   (defun test-function (x) (equal x A-PARAMETER)))

and use it as in your example.
Then A-PARAMETER is not global anymore (but test-function is).

Ralf

--
-- 
to get PGP keys: finger ···@cnve.rz.uni-jena.de (or from public key servers)
pgp public key fingerprints:
A3 93 A6 0B E2 8F 04 25  5B 3C 00 F6 55 E5 64 20  [1024 bit]
64 36 31 D8 7A 73 20 F7  CA 6A DA 02 AF 29 46 1C  [2047 bit]
From: Pete Halverson
Subject: Re: Q: passing parameters
Date: 
Message-ID: <pch-0910950833550001@198.3.157.39>
In article <··········@fsuj01.rz.uni-jena.de>, ···@rz.uni-jena.de (Ralf
Muschall) wrote:

> In article <···················@sweetbay.will.uiuc.edu> Dragos Manolescu
<········@uiuc.edu> writes:
> 
> >I was wondering if there is possible to supply (constant) data to any
> >of the mapping functions (e.g. mapcar, remove-if, etc.) without
> >relying to global variables.
 ....
> 
> If you don't want to use a global variable, you either
> have to enter its value as a constant (e.g. a literal 6
> instead of A-PARAMETER), or pass it as an argument to the
> function which uses test-function.

I replied to the original poster via e-mail, but Mr. Muschall's response
suggests I probably should have posted it to the group as well.  

One can simply use an anonymous LAMBDA function to capture the binding of
A-PARAMETER and pass that to the mapping function, e.g.

   (remove-if #'(lambda (an-element)
                   (equal an-alement a-parameter))
              a-list)

No globals (either variables or functions), no worrying about literals vs.
variables, no modifying argument lists, just say what you mean. 

Like the bumper sticker (sort of) says, you can take away my lexical
closures only by prying them from my cold dead fingers.

pch