Sujet : Re: help me with this function
De : No_spamming (at) *nospam* noWhere_7073.org (B. Pym)
Groupes : comp.lang.lispDate : 02. Jul 2024, 11:44:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v60i57$1jclv$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
i'm trying to write a function that takes two arguments - one is
an ato the other is a list of lists - for each list within the
list, if the atom matches its first memeber, i want it's second
member to be added to a master list and finally returned- for
example:
(setq mylist '((a b)(a c)(a d)))
(myfunc 'a lst)
and myfunc would return
(b c d)
Kenny Tilton wrote:
I do not know of a one-step solution, but you could try:
(defun cullCar (match lists)
(delete-if #'null (mapcar #'(lambda (list)
(when (eql match (car list))
(cadr list)))
lists)))
This would be inefficent where many non-matches occur. Doesn't
the loop macro have some neat features for this? (Don't use it
myself.)
Scheme
(define (myfunc x lst)
(filter-map
(lambda(xs) (and (equal? x (car xs)) (cadr xs)))
lst))
(myfunc 'b '((b 2) (c 3) (b 4) (d 5) (b 6)))
===>
(2 4 6)