谁能给我一些关于这个问题的提示(家谱)?
它来自我的家庭作业。有一个家谱
a + b
/ | | \
c+u d+c e+w f
/ | \ / \
m+x n+y o p q
|
r
a 和 b 是最古老的。而每个已婚人士的第二个人都不是原生家庭的一部分。 现在我需要编写配偶、兄弟姐妹、孩子、孙子、父母和祖父母函数。
我写的清单如下: ( (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) )
我的兄弟函数有一些问题,这是我的代码。
(defun sibling (arglst lst)
(cond
((eql
arglst (cdr (car lst)))
(rest (cdr lst))
)
(T (sibling (rest lst) arglst))
)
我知道这是错误的,但我不知道如何修改它..而且我还需要其他功能的帮助。希望能从你们那里得到一些提示。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于这是家庭作业,我不会给出完整的解决方案,但这应该足以让您解决其余问题:
尝试一下:
例如,现在要找到祖父母,您只需了解祖父母是什么:( ) 父母双方的父母。然后,问问自己,孙子们过得怎么样。最后,鉴于此示例,
spouse
函数应该相当简单。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
spouse
function should be rather easy, given this example.例如,我不知道为什么它只能返回第一级和第二级。 a 返回 b,c 返回 u 。但是当我输入 m 时,它返回一个错误:
- MEMBER:正确的列表不得以 F 结尾
。我检查了代码,没有发现任何问题。为什么它不能搜索第三层?但它可以找到孙子,所以我想如果它可以做孙子搜索为什么它不能做配偶搜索?
Member
函数有问题吗?无论如何,您的代码非常简单且易于阅读和理解。多谢。I don't know why it can only return first level and second level,for example. a returns b, c returns u . but when I entere m ,it returns an erro :
- MEMBER: A proper list must not end with F
.I checked the code and didn't find any problems. why it cannot search the third level? but it can find grandchildren,so I think if it can do grandchildren search why it cannot do spouse search? is there something wrong with
Member
function? anyway, your code is really simple and easy to read and understand. Thanks a lot.