How the yin-yang puzzle works?

Posted by Hrundik on Stack Overflow See other posts from Stack Overflow or by Hrundik
Published on 2010-04-22T21:32:38Z Indexed on 2010/04/23 20:33 UTC
Read the original article Hit count: 1155

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about Scheme

Related posts about callcc