Unlambda d 函数

发布于 2024-10-04 23:33:25 字数 895 浏览 0 评论 0原文

我想我需要详细说明 D 函数在 unlambda 中的工作原理。现在我正在尝试使用 Y 组合器创建一个函数(阶乘),但它总是会导致某种无限循环。或者段错误,取决于解释器。我很确定 D 就是我想在这里使用的。我尝试了这个:

``d```sii``sii`.xi

它有相同的无限循环。有人认为他们可以帮助我理解 unlambda 中的 D 吗?

...

在 unlambda 表示法中,我的功能是

```s``s``s`ks``s`kki``s``s`ks`ki`ki``s``s`ks``s`kki``s``s`ks`ki`ki``s`k`s``s``s``s``si`k`ki`k``s``si`k`ki`kk`k`ki`k`s`sk``s`k`s``s`ksk``s``s`ksk`k``s``si`k``s``s``s``si`ki`k`ki`k`ki`s``s`ksk`k`k`kk

Y= ``s``s``s`ks``s`kki``s``s`ks`ki`ki``s``s`ks``s`kki``s``s`ks`ki`ki

Factorial = Y(\xy.0y1(My(x(Sy))))

0 = ``s``s``si`k`ki`k``s``si`k`ki`kk`k`ki (Returns K if it's 0 in church numerals, Returns KI if it's something else.)

M = ``s`ksk (Prefix multiplier of church numerals)

S = ``s``si`k``s``s``s``si`ki`k`ki`k`ki`s``s`ksk`k`k`kk (Decrements a church integer)

我很确定如果它被正常评估,左边在前,它会起作用,但我不确定。

提前致谢。

I think I need some elaboration on how the D function works in unlambda. Right now I'm trying to make a function (factorial) with the Y combinator, but it always results in some kind of infinite loop. Or segfault, depending on the interpreter. I'm pretty sure D is what I want to use here. I tried this:

``d```sii``sii`.xi

and it had the same infinite loop. Does anyone think they could help me understand D in unlambda?

...

In unlambda notation, my function is

```s``s``s`ks``s`kki``s``s`ks`ki`ki``s``s`ks``s`kki``s``s`ks`ki`ki``s`k`s``s``s``s``si`k`ki`k``s``si`k`ki`kk`k`ki`k`s`sk``s`k`s``s`ksk``s``s`ksk`k``s``si`k``s``s``s``si`ki`k`ki`k`ki`s``s`ksk`k`k`kk

Y= ``s``s``s`ks``s`kki``s``s`ks`ki`ki``s``s`ks``s`kki``s``s`ks`ki`ki

Factorial = Y(\xy.0y1(My(x(Sy))))

0 = ``s``s``si`k`ki`k``s``si`k`ki`kk`k`ki (Returns K if it's 0 in church numerals, Returns KI if it's something else.)

M = ``s`ksk (Prefix multiplier of church numerals)

S = ``s``si`k``s``s``s``si`ki`k`ki`k`ki`s``s`ksk`k`k`kk (Decrements a church integer)

I'm pretty sure that if it were evaluated normally, with the left first, it would work, but I'm not sure.

Thanks in advance.

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

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

发布评论

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

评论(1

呆° 2024-10-11 23:33:25

我真的不明白 d 如何帮助阶乘函数,但说明 d 的作用很简单:

 `.1` .2i => 21
``.1`d.2i => 12

在第一种情况下,.2 在 .1 之前求值。

在第二种情况下,.2 通过“受保护”的 .1 传递,仅从外部进行评估。

I don't really see how d could help a factorial function, but an illustration of what d does is easy:

 `.1` .2i => 21
``.1`d.2i => 12

In the first case, .2 is evaluated before .1, on grounds of the eager evaluation rule.

In the second case, .2 is passed through .1 "protected", only to be evaluated from the outside.

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