![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 7
Rep Power: 0
![]() |
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))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)))))(search-for 'children jane) Any help would be greatly appreciated. Last edited by AusTex; Jun 19th, 2005 at 2:06 PM. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|