Created
March 26, 2017 03:32
-
-
Save DadgadCafe/4e7166f4bfa703e1aee905fd1e969a10 to your computer and use it in GitHub Desktop.
yin-yang problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; detailed continuation usage, see previous gist: https://gist.github.com/DadgadCafe/07b0b50bf9537522fed09b3dc8df2784 | |
(define call/cc call-with-current-continuation) | |
(let* ((yin | |
((lambda (cc) (display #\@) cc) | |
(call/cc (lambda (c) c)))) | |
(yang | |
((lambda (cc) (display #\*) cc) | |
(call/cc (lambda (c) c))))) | |
(yin yang)) | |
;; yang catches previous yin | |
;; yin becomes previous yang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// chain: ccYin -> yang -> cont -> ccYin(previous) | |
// obviously, Maximum call stack size exceeded | |
function makeYang (cont) { | |
ccYin = yang | |
function yang () { | |
console.log('*') | |
cont() | |
} | |
} | |
function yin () { | |
console.log('@') | |
makeYang(ccYin) | |
ccYin() | |
} | |
let ccYin = yin | |
ccYin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call/cc is a black hole, terminates once it is applied with parameter.