(setq mylist '((a b)(a c)(a d)))
(myfunc 'a lst)
and myfunc would return
(b c d)
i've tried using with-collection and collect but i can't get them to work
properly- anyone have any ideas?
thanks,
kevin
| i'm trying to write a function that takes two arguments - one is an
| atom 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)
|
| i've tried using with-collection and collect but i can't get them to work
| properly- anyone have any ideas?
the body of a function with args car and list could be quite simple:
(mapcan (lambda (cons) (if (eq (car cons) car) (cdr cons))) list)
it is more instructive for you to write a recursive function. you may note
that (myfunc car list) is identical to (myfunc car (cdr list)) if (car list)
does not match car. you get the idea.
#<Erik>
--
in my next life, I want to be my cat
(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.)