如何实现haskell`\\`函数?
在 haskell 中, [1,2,3,4,5,6,7] \\ [4,5,6]
将返回 [1,2,3,7]
代码>.现在我想使用 clisp 实现相同的功能。到目前为止,我发现 set-difference
有效:
(set-difference '(1 2 3 4 5 6 7) '(4 5 6))
还有其他解决方案吗?
In haskell, [1,2,3,4,5,6,7] \\ [4,5,6]
will return [1,2,3,7]
. Now i want to implement the same function using clisp. Up to now i find set-difference
works :
(set-difference '(1 2 3 4 5 6 7) '(4 5 6))
Are there any other solution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是 haskell 库源代码的相关部分。也许你可以直接翻译这些定义。我认为它没有使用 Haskell 特有的任何东西。
(来源来自 http://haskell。 org/ghc/docs/latest/html/libraries/base/src/Data-List.html)
Here are relevant bits of haskell library source. Maybe you can translate these definitions directly. I don't think it uses anything specific to Haskell.
(the source is from http://haskell.org/ghc/docs/latest/html/libraries/base/src/Data-List.html)
我不太了解 Common Lisp,所以这里是 Ben 粘贴的代码的方案实现:
其中
fold
和car+cdr
来自 SRFI 1,并且receive
来自 SRFI 8。如果我们允许自己使用 SRFI 26 的
cut
形式,那么我们就有了一个看起来更接近 Haskell 版本的解决方案(因为后者至少在两个地方使用柯里化):I don't know Common Lisp that well, so here's a Scheme implementation of the code pasted by Ben:
where
fold
andcar+cdr
come from SRFI 1, andreceive
comes from SRFI 8.If we will allow ourselves the use of SRFI 26's
cut
form, then we have a solution that looks even closer to the Haskell version (since the latter uses currying in at least two places):