如何使用 S、K 和 I 组合符编写一个空列表?

发布于 2024-07-30 17:19:06 字数 430 浏览 5 评论 0原文

我知道:

(cons [p] [q]) is ((s ((s i) (k [p]))) (k [q]))
(car [lst]) is ([lst] k)
(cdr [lst]) is ([lst] (k i))

我想写一个像这样的列表

(cons [a] (cons [b] (cons [c] [nil])))

,它将是这样的:

((s ((s i) (k [a]))) (k ((s ((s i) (k [b]))) (k ((s ((s i) (k [c]))) (k [nil]))))))

但我不知道如何将“nil”编译成 S、K 和 I 组合器。 有人知道吗?

提前致谢, 埃德温·何塞·帕拉辛卡尔

I know that:

(cons [p] [q]) is ((s ((s i) (k [p]))) (k [q]))
(car [lst]) is ([lst] k)
(cdr [lst]) is ([lst] (k i))

I want to write a list like this

(cons [a] (cons [b] (cons [c] [nil])))

, which is going to be something like this:

((s ((s i) (k [a]))) (k ((s ((s i) (k [b]))) (k ((s ((s i) (k [c]))) (k [nil]))))))

But I don't know how to compile 'nil' into S, K and I combinators. Does anyone know?

Thanks in advance,
Edwin Jose Palathinkal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长不大的小祸害 2024-08-06 17:19:06

您从 nil 表示中唯一需要的是能够识别它 - 编写一些 null? 谓词,为 nil 返回“true” > 和“false”对于所有其他对。 这意味着答案取决于您对真/假的表述。 由于通常选择λxy.xλxy.ynil的方便编码是λf.[true]. 现在将其转换为 SKI 非常容易(我不会在这里这样做,因为它看起来像家庭作业......)。

(此外,考虑到 nil 的表示,实现一个 null? 谓词是一个很好的练习。)

The only thing you need from a nil representation is to be able to identify it -- write some null? predicate that returns "true" for nil and "false" for all other pairs. This means that the answer depends on your representation of true/false. With the common choice of λxy.x and λxy.y, a convenient encoding for nil is λf.[true]. Translating this to SKI is very easy now (and I won't do it here, since it looks like homework...).

(Also, implementing a null? predicate given this representation for nil is a good exercise.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文