From: Kevin P Chugh
Subject: help me with this function
Date: 
Message-ID: <4ivotl$akh@azure.acsu.buffalo.edu>
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)

i've tried using with-collection and collect but i can't get them to work
properly- anyone have any ideas?

thanks,
kevin

From: Pete Grant
Subject: Re: help me with this function
Date: 
Message-ID: <4j1r9c$8ss@news1.h1.usa.pipeline.com>
On Mar 23, 1996 02:50:29 in article <help me with this function>,
······@cs.buffalo.edu (Kevin P Chugh)' wrote: 
 
 
>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) 
> 
>i've tried using with-collection and collect but i can't get them to work 
>properly- anyone have any ideas? 
> 
(defun myfunc (item list) 
 (mapcan #'(lambda (x) 
                  (and (eql item (car x)) 
                        (cdr x))) 
                 list)) 
 
If on a Symbolics machine (may work with others also),  
 
(defun myfunc (item list) 
 (loop for (key data) in list 
   when (eql item key) 
      collect data)) 
 
-- 
 
Pete Grant 
Kalevi, Inc. 
Sofware Engineering
From: Erik Naggum
Subject: Re: help me with this function
Date: 
Message-ID: <3036617570947380@arcana.naggum.no>
[Kevin P Chugh]

|   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
From: Kenny Tilton
Subject: Re: help me with this function
Date: 
Message-ID: <4j9mar$3n@betty.bway.net>
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.)