The yin yang puzzle was written in Scheme. Since it uses call/cc, it is not possible to express it in a pure lambda expression, unless we do a CPS transform.
However, given the fact that $\lambda \mu$-calculus have the power to model call/cc, is it possible to write an equivalent $\lambda \mu$-expression? I am still learning $\lambda \mu$-deductions, so this would be a good example to show how the deduction works.
There is no need to model the "display" command in a pure expression. Ideally only showing how the calculus keep looping and evaluates diffident terms again and again.
UPDATE My translation in $\lambda$-expression with CPS:
(λcallcc.callcc (λyin.callcc (λyang.yin yang))(λcc.cc cc)
In CPS, (λcc.cc cc)
is what "call with current continuation" means. So the expression takes it as a parameter. This will result in assign the sub-expression starts λyin
assign its continuation into parameter yin
. And then in the body, the second callcc assigns the yang
of sub-expression starts λyang
into itself. Finally, apply yin yang
.
Note the above translate is not full CPS, only the concept of call/cc has been translated. But it provides the same behavior and it is not hard to do a full CPS translate.