如何使用 S、K 和 I 组合符编写一个空列表?
我知道:
(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您从
nil
表示中唯一需要的是能够识别它 - 编写一些null?
谓词,为nil
返回“true” > 和“false”对于所有其他对。 这意味着答案取决于您对真/假的表述。 由于通常选择λxy.x
和λxy.y
,nil
的方便编码是λf.[true]. 现在将其转换为 SKI 非常容易(我不会在这里这样做,因为它看起来像家庭作业......)。
(此外,考虑到
nil
的表示,实现一个null?
谓词是一个很好的练习。)The only thing you need from a
nil
representation is to be able to identify it -- write somenull?
predicate that returns "true" fornil
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 fornil
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 fornil
is a good exercise.)