It comes from my homework assignments. There is a family tree
a + b
/ | | \
c+u d+c e+w f
/ | \ / \
m+x n+y o p q
|
r
a and b is the oldest. and every married people the second person is not part of the original family.
Now I need to write the spouse, sibling, children ,grandchildren, parents and grandparents function.
I wrote the list as below:
( (father mother) chlid1 child2 child3)
(((a b) c d e f) ((c u) m n o) ((d v) nil) ((e w) p q) (f nil) ((m x) r) ((n y) nil) (o nil) (p nil) (q nil) )
I have some problems with sibling function, here is my code.
(defun sibling (arglst lst)
(cond
((eql
arglst (cdr (car lst)))
(rest (cdr lst))
)
(T (sibling (rest lst) arglst))
)
I knew it was wrong, but I don’t how to revise it.. and I also need some help with other functions. hope can get some hints from u guys.
Since this is homework, I won’t give the full solution, but this should suffice for you to solve the rest:
Try it:
Now, to find the grandparents for example, you just have to understand what grandparents are: (A list of) The parents of both parents. Then, ask yourself how it is for grandchildren. Finally, the
spousefunction should be rather easy, given this example.