Last active
July 6, 2017 07:30
-
-
Save ide-an/5884655 to your computer and use it in GitHub Desktop.
yin-yang puzzleをJavaScript(Rhino)に移植してみた。
参考 http://practical-scheme.net/wiliki/wiliki.cgi?Scheme%3Acall%2Fcc%E3%83%91%E3%82%BA%E3%83%AB
This file contains 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
var callcc = function(f){ | |
var c = new Continuation(); | |
return f(c); | |
}; | |
// Original code | |
// (let* ((yin ((lambda (cc) (newline) cc) | |
// (call/cc (lambda (bar) bar)))) | |
// (yang ((lambda (cc) (display "*") cc) | |
// (call/cc (lambda (foo) foo))))) | |
// (yin yang)) | |
// This code is not correct... | |
// var yin = function(cc){ | |
// print("----"); | |
// java.lang.Thread.sleep(1000); | |
// return cc; | |
// }(callcc(function(bar){ | |
// return bar; | |
// })); | |
// var yang = function(cc){ | |
// print("*"); | |
// java.lang.Thread.sleep(1000); | |
// return cc; | |
// }(callcc(function(foo){ | |
// return foo; | |
// })); | |
// yin(yang); | |
// This code is correct!!! | |
(function(yin){ | |
return function(yang){ | |
return yin(yang); | |
}(function(cc){ | |
print("*"); | |
java.lang.Thread.sleep(1000); | |
return cc; | |
}(callcc(function(foo){ | |
return foo; | |
}))); | |
}(function(cc){ | |
print("---"); | |
java.lang.Thread.sleep(1000); | |
return cc; | |
}(callcc(function(bar){ | |
return bar; | |
})))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment