I'm sure this is a very beginner question in lisp, as I am just learning the language.
I have a function in clisp called count. It counts the number of times a given atom appears in a list. What I'd like to do is be able to call count multiple times with different parameters, but the same list to search.
For example, I'd like to count the number of 'A
, 'B
, and 'C
in the list, hypothetically. I was hoping I could do something like this:
(mapcar 'count '(A B C) myList)
I've figured out that this doesn't work because each of the elements in '(A B C)
are being paired up with only one of the elements in myList. What is the appropriate idiomatic way to apply a function with an additional input parameter to each item in a list?
To further clarify, I'd like to be able to take '(A B C)
and '(A A B C C C)
as input and produce (2 1 3)
.
To call the function count
repeatedly with each item from a list (A B C)
, every time counting matching items the same sequence mylist
:
(mapcar (lambda (x) (count x mylist)) '(A B C))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With