Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
help me with this function
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kevin P Chugh  
View profile  
 More options Mar 23 1996, 3:00 am
Newsgroups: comp.lang.lisp
From: ch...@cs.buffalo.edu (Kevin P Chugh)
Date: 1996/03/23
Subject: help me with this function
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Grant  
View profile  
 More options Mar 23 1996, 3:00 am
Newsgroups: comp.lang.lisp
From: gra...@usa.pipeline.com(Pete Grant)
Date: 1996/03/23
Subject: Re: help me with this function
On Mar 23, 1996 02:50:29 in article <help me with this function>,
'ch...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Mar 24 1996, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 1996/03/24
Subject: Re: help me with this function
[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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenny Tilton  
View profile  
 More options Mar 26 1996, 3:00 am
Newsgroups: comp.lang.lisp
From: Kenny Tilton <t...@qi-labs.com>
Date: 1996/03/26
Subject: Re: help me with this function
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.)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »