Hi!
does anybody know how to use a mapping function with functions instead
of lists?
I've written some auxiliary functions and instead of calling them
separately with many conditions I want to use a mapping function like
that:
(map #' (lambda (i) (do-something)) '(test1 test2 test3 test4))
My code looks like:
(test1)
(when (=T found-nothing)
(test2)
(when (=T found-nothing)
(test3)....
Thanks!
Daniela
In article <·······················@d57g2000hsg.googlegroups.com>,
··············@web.de wrote:
> Hi!
>
> does anybody know how to use a mapping function with functions instead
> of lists?
> I've written some auxiliary functions and instead of calling them
> separately with many conditions I want to use a mapping function like
> that:
>
> (map #' (lambda (i) (do-something)) '(test1 test2 test3 test4))
>
> My code looks like:
>
> (test1)
> (when (=T found-nothing)
> (test2)
> (when (=T found-nothing)
> (test3)....
>
>
> Thanks!
> Daniela
Which Lisp are you using? Have you read some introductory text?
Do you have a reference where you can look up the
function documentation?
How do you call a function?
a) (my-function arg1 arg2 ...)
or
b) with FUNCALL or APPLY
How do you create a list of function objects?
(list #'f1 #'f2 #'f3)
How do you map over a list of functions?
? (mapcar (lambda (f) (funcall f pi)) (list #'sin #'cos))
(1.2246063538223773D-16 -1.0D0)
You can also map over two (or more) lists:
? (mapcar (lambda (f a) (funcall f a))
(list #'sin #'cos)
(list 1 2))
(0.84147096 -0.41614684)
Instead of MAP (and related like MAPCAR), see also
EVERY, SOME, ...
--
http://lispm.dyndns.org
Le Tue, 27 Mar 2007 09:43:59 +0100, Rainer Joswig a écrit:
>> does anybody know how to use a mapping function with functions
>> instead of lists?
There are many ways to interpret that... Could you instead show a
specific example of what you *want to do*?
Curiously,
Pierre
--
···········@levallois.eu.org
OpenPGP 0xD9D50D8A
On Mar 27, 9:12 am, ··············@web.de wrote:
> Hi!
>
> does anybody know how to use a mapping function with functions instead
> of lists?
> I've written some auxiliary functions and instead of calling them
> separately with many conditions I want to use a mapping function like
> that:
>
> (map #' (lambda (i) (do-something)) '(test1 test2 test3 test4))
>
> My code looks like:
>
> (test1)
> (when (=T found-nothing)
> (test2)
> (when (=T found-nothing)
> (test3)....
>
> Thanks!
> Daniela
Daniela
1. Are you a common lisper or a schemer
If you're schemer ask at comp.lang .scheme
else read the hyperspec:
http://www.lisp.org/HyperSpec/Body/fun_map.html
where it clearly states that map works on SEQUENCES.
Explain what do you want to achieve , you're problem
little bit broader to get better answers
cheers
bobi
On Wed, 28 Mar 2007 13:51:39 +0200, fireblade
<·················@gmail.com> wrote:
> On Mar 27, 9:12 am, ··············@web.de wrote:
>> Hi!
>>
>> does anybody know how to use a mapping function with functions instead
>> of lists?
>> I've written some auxiliary functions and instead of calling them
>> separately with many conditions I want to use a mapping function like
>> that:
>>
>> (map #' (lambda (i) (do-something)) '(test1 test2 test3 test4))
>>
>> My code looks like:
>>
>> (test1)
>> (when (=T found-nothing)
>> (test2)
>> (when (=T found-nothing)
>> (test3)....
>>
>> Thanks!
>> Daniela
>
> Daniela
> 1. Are you a common lisper or a schemer
> If you're schemer ask at comp.lang .scheme
> else read the hyperspec:
> http://www.lisp.org/HyperSpec/Body/fun_map.html
> where it clearly states that map works on SEQUENCES.
>
> Explain what do you want to achieve , you're problem
> little bit broader to get better answers
> cheers
> bobi
>
>
>
It is CL. Look at the #'.
(defun test1 ())
...
(defun testn ())
(find-if-not (lambda (fun) (=T (funcall fun)) (list #'test1 ... #'testn)))
I see the when's are nested. find-if-not will continue testing until the
test
is false.
or something like that.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Hi!
I use SBCL.
The content is a test on rules. I have to search which rule (i.e.
which rule: each test looks for a specific rule) matches with my input
variables. Therefore I have many different tests. If a test does not
match, I take the next one and so on.
(defun test1() ...)
(defun test2()...)
So far I'm using a long and complicated nested when-condition:
(test1)
(when (=T found-nothing)
(test2)
(when (=T found-nothing)
(test3)....
I think John's suggestion should match with my problem. Otherwise I
would be encouraged to hear an other suggestion or what's going wrong.
Thank you so long!
Daniela
If I use a mapping function or a similar function with functions as a
list, how can I handle the function's parameters?
For example:
My function test1 has 3 parameter:
(defun test1 (a b c) ...)
Thanks!
Daniela
On 28 Mar 2007 09:01:23 -0700, ··············@web.de tried to confuse everyone
with this message:
>Hi!
>
>I use SBCL.
>The content is a test on rules. I have to search which rule (i.e.
>which rule: each test looks for a specific rule) matches with my input
>variables. Therefore I have many different tests. If a test does not
>match, I take the next one and so on.
>
>(defun test1() ...)
>(defun test2()...)
>
>So far I'm using a long and complicated nested when-condition:
>
>(test1)
> (when (=T found-nothing)
> (test2)
> (when (=T found-nothing)
> (test3)....
>
>I think John's suggestion should match with my problem. Otherwise I
>would be encouraged to hear an other suggestion or what's going wrong.
>
You might find SOME of these functions interesting:
http://www.lisp.org/HyperSpec/Body/fun_everycm_s_erycm_notany.html
--
|Don't believe this - you're not worthless ,gr---------.ru
|It's us against millions and we can't take them all... | ue il |
|But we can take them on! | @ma |
| (A Wilhelm Scream - The Rip) |______________|
··············@web.de wrote:
> Hi!
>
> I use SBCL.
> The content is a test on rules. I have to search which rule (i.e.
> which rule: each test looks for a specific rule) matches with my input
> variables. Therefore I have many different tests. If a test does not
> match, I take the next one and so on.
>
> (defun test1() ...)
> (defun test2()...)
>
> So far I'm using a long and complicated nested when-condition:
>
> (test1)
> (when (=T found-nothing)
> (test2)
> (when (=T found-nothing)
> (test3)....
>
> I think John's suggestion should match with my problem. Otherwise I
> would be encouraged to hear an other suggestion or what's going wrong.
Can you tell us something about the problem that you actually want to
solve? Maybe there is a better way to structure your solution.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
> Can you tell us something about the problem that you actually want to
> solve? Maybe there is a better way to structure your solution.
>
> Pascal
The basic is a two-dimensional table with n input variables and n
output variables. These variables are boolean variables and some of
the output variables depend on some of the input variables by the use
of boolean rules.
For example:
input output
A B C | D E F
--------------
1 0 0 | 1 1 0
0 1 1 | 0 1 0
....
I already know which of the output variables depend on which of the
input variables. The next step is to find the matching boolean rule, I
only use the rules AND, OR, NOT and EQUAL. In this example one rule
could be: A == D.
Therefore I wrote some functions testing the different rules, e.g.
(defun test-AND (...) ...)
(defun test-OR (...) ...)
These functions test whether all values of an input variable match
with all values of an output variable using a specific rule (e.g.
(test-AND)). If the rule does not match the next rule/test follows.
I hope that you can now understand my problem better.
Daniela
··············@web.de writes:
>> Can you tell us something about the problem that you actually want to
>> solve? Maybe there is a better way to structure your solution.
>>
>> Pascal
>
>
> The basic is a two-dimensional table with n input variables and n
> output variables. These variables are boolean variables and some of
> the output variables depend on some of the input variables by the use
> of boolean rules.
> For example:
>
> input output
> A B C | D E F
> --------------
> 1 0 0 | 1 1 0
> 0 1 1 | 0 1 0
> ....
>
> I already know which of the output variables depend on which of the
> input variables. The next step is to find the matching boolean rule, I
> only use the rules AND, OR, NOT and EQUAL. In this example one rule
> could be: A == D.
> Therefore I wrote some functions testing the different rules, e.g.
> (defun test-AND (...) ...)
> (defun test-OR (...) ...)
> These functions test whether all values of an input variable match
> with all values of an output variable using a specific rule (e.g.
> (test-AND)). If the rule does not match the next rule/test follows.
>
> I hope that you can now understand my problem better.
Have a look at karnaugh-solve in:
http://darcs.informatimago.com/emacs/pjb-sources.el
You should be able to convert it to common-lisp easily.
Note that =T is suspicious. Would that be (defun =T (x) (eq x T)) ?
You'd better just test the boolean:
(test1)
(when found-nothing
(test2)
(when found-nothing
...))
Note that found-nothing is suspicious. It looks like a global
variable. Or in anycase, a variable that is modified by side effect
in the functions test1, test2, etc. This is not a good idea.
Twicely, for the double negative it implies. It would be better to
have the test functions return a boolean indicating if they've found
something, and to write:
(unless (test1)
(unless (test2)
...))
Then you could easily write it in a higher level:
(unless (some (lambda (test) (funcall test))
(list (function test1) (function test2) (function test3) ...))
;; executed when nothing's found.
...)
--
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
From: Mark Cox
Subject: Re: mapping functions with functions as parameters?
Date:
Message-ID: <460b07e0$1@news.qut.edu.au>
Hi Daniela,
This problem triggered a memory from my undergraduate days. I think the
Karnaugh map algorithm might be what you're looking for here.
http://en.wikipedia.org/wiki/Karnaugh
Mark
··············@web.de wrote:
>> Can you tell us something about the problem that you actually want to
>> solve? Maybe there is a better way to structure your solution.
>>
>> Pascal
>
>
> The basic is a two-dimensional table with n input variables and n
> output variables. These variables are boolean variables and some of
> the output variables depend on some of the input variables by the use
> of boolean rules.
> For example:
>
> input output
> A B C | D E F
> --------------
> 1 0 0 | 1 1 0
> 0 1 1 | 0 1 0
> .....
>
> I already know which of the output variables depend on which of the
> input variables. The next step is to find the matching boolean rule, I
> only use the rules AND, OR, NOT and EQUAL. In this example one rule
> could be: A == D.
> Therefore I wrote some functions testing the different rules, e.g.
> (defun test-AND (...) ...)
> (defun test-OR (...) ...)
> These functions test whether all values of an input variable match
> with all values of an output variable using a specific rule (e.g.
> (test-AND)). If the rule does not match the next rule/test follows.
>
> I hope that you can now understand my problem better.
>
> Daniela
>
>