How the yin-yang puzzle works?
- by Hrundik
I'm trying to grasp the semantics of call/cc in Scheme, and the Wikipedia page on continuations shows the yin-yang puzzle as an example:
(let* ((yin
((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c))))
(yang
((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) c)))) )
(yin yang))
It should output @\*@\**@\**\*@\**\**@...,
but I don't understand why; I'd expect it to output @\*@\**\**\**\**\*...
Can somebody explain in detail why the yin-yang puzzle works the way it works?