开发者

Unlambda d function

开发者 https://www.devze.com 2023-01-27 11:23 出处:网络
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

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 understan开发者_如何转开发d 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号