Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 19th, 2005, 3:22 AM   #1
AusTex
Newbie
 
Join Date: Feb 2005
Posts: 7
Rep Power: 0 AusTex is on a distinguished road
Lisp help needed

I was hoping to get some help with a couple of problems I am working on.
On both problems I am working with a list of form:
 (setf jane '((jane (address
                      (number 1201)
                      (street main)
                      (city san-antonio)
                      (state texas)
                      (zip 75438))
                    (parents
                      (father pete)
                      (mother sue))
                    (children bob)
                      (name jane)
                      (weight 120))))

First, I need to define a function that receives an association list of the form above and returns the following list:

output --> (jane father is pete mother is sue)

I have not defined a function yet, but I am able to produce the above output, without the "is" string, with the follwing code:
(defun info () (append (first (list (first (rest (second (rest (first jane))))) 
                       (second (rest (second (rest (first jane)))))))
                       (second (list (first (rest (second (rest (first jane))))) 
                       (second (rest (second (rest (first jane)))))))))



(append (rest (fifth (first jane)))
             (info))
The above code outputs (JANE FATHER PETE MOTHER SUE)
My question is, how do I get the "is" string in (jane father is pete mother is sue) outputed?


For my second problem, I need to define a function that receives a key and an association list of the form above and returns the list in which key is the first member of.

I can, for example, produce the value of children, which is bob, with the follwing code:
(second (assoc 'children (rest (first jane))))

How come when I define a function with the code below, I get NIL when searching for the value of children?
(defun search-for (key in-list)
                    (second (assoc 'key (rest (first in-list)))))
Searching with:
(search-for 'children jane)

Any help would be greatly appreciated.

Last edited by AusTex; Jun 19th, 2005 at 2:06 PM.
AusTex is offline   Reply With Quote
Old Jun 24th, 2005, 10:26 AM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
for the first problem... split the (father pete) and (mother sue) lists and cons 'is to the second of each, then do your appending.

for the second problem, make your search function recursive so it can find atoms in the sublists.

hope this gentle guidance helps
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC