Subject: Re: mapcar using a function with one argument fixed
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 04 Dec 2007 22:47:23 -0600
Newsgroups: comp.lang.lisp
Message-ID: <vMqdnQHag-TGsMvanZ2dnUVZ_ternZ2d@speakeasy.net>
Maciej Katafiasz  <mathrick@gmail.com> wrote:
+---------------
| skrev andrew.polonsky:
| > What is the most _elegant_ way to mapcar a list with a function that
| > takes multiple values, setting some constant.  Is there no neater
| > alternative to
| > (mapcar (lambda (x) (my-function x a b c)) my-list)
| 
| There are some libraries that provide you with CURRY, for example arnesi. 
| You could also use #L() reader macro, from the same library:
| 
| (mapcar #L(my-function !1 a b c) my-list)
| 
| http://common-lisp.net/project/bese/docs/arnesi/html/api/function_005FIT.BESE.ARNESI_003A_003ASHARPL-READER.html
+---------------

How neat hacks *do* get re-invented... and re-invented...  ;-}  ;-}

I call my equivalent of that #$, and use $1, $2, ... $9 as the names
of the args, as in the shell:

    > (mapcar #$(+ (* 100 $2) $1) '(1 2 3 4) '(5 6 7 8) '(9 10 11 12))

    (501 602 703 804)
    > 

I also provide a $* which gets stuck after &REST, but that doesn't
work very well, since unlike Arenesi's #L I don't count to see what
the highest ${n} was, so $* only starts with the 10th arg. (Oops!)

I should re-do my version to count the ${n} args [and/or use #{n}$
like Arenesi does] so as to place the $* properly...


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607