如何编写一个接受两个列表并返回四个列表的方案函数
我有 2 个元素列表 '(abc) '(dbf),并且想要在一个结果中查找差异、并集和交集。 那可能吗? 如何?
我编写了一个成员函数来检查第二个列表中是否存在第一个列表中的汽车,但我无法将成员扔到新列表中。
(define (checkResult lis1 lis2)
(cond...........
))
(checkresult '( a b c) '(d b f))
我的结果应该是 (( ac) (df) (abcdf) (b))
。
I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How?
I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a member to the new list.
(define (checkResult lis1 lis2)
(cond...........
))
(checkresult '( a b c) '(d b f))
My result should be (( a c) (d f) (a b c d f) (b))
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
就像其他人所说的那样,您需要做的就是创建单独的函数来计算两个集合的交集、并集和减法,并从 checkresult 中调用它们:
以下是一些示例并集、交集和减法函数:
注意:因为这些是集合,顺序无关紧要,结果未排序。 此外,这些函数假设输入是集合,因此不会执行超出联合所需的任何重复检查。
Like others have said, all you need to do is create separate functions to compute the intersection, union, and subtraction of the two sets, and call them from checkresult:
Here are some example union, intersection, and subtraction functions:
Note: since these are sets and order doesn't matter, the results are not sorted. Also, the functions assume that the inputs are sets, and therefore don't do any duplicate checking beyond what's required for union.
当然有可能。 假设您有计算差异、并集交集等的函数:
Sure it is possible. Assuming that you have function to compute the differences, union intersection etc:
当然有可能。 这里有一些提示:
Sure it's possible. Here are a couple hints:
除了 Charlie Martin 和 tomjen 的答案之外,我还提出了以下来源:
并集交集和差分
可以找到不同函数的实现以及很好的解释。
On top of Charlie Martin's and tomjen's answers, I have come up with this source:
Union Intersection and Difference
Implementation of the distinct functions can be found with nice explanations.