call/ccと副作用
http://practical-scheme.net/wiliki/wiliki.cgi?Scheme%3acall%2fcc%e3%81%a8%e5%89%af%e4%bd%9c%e7%94%a8
[id:sumii:20061121]
前に紹介したFamkeの論文にも、
We implement threads by using first class continuations in Clean, without the usage of call/CC (with, according to Thielecke [6] can be dangerous).
...
[6] Hayo Thielecke. Using a continuation twice and its implications for the expressive power of call/CC. Higher-Order and Symbolic Computation, 12(1):47-73, 1999.
とあって、へーそーなのか、と思ってました。
私には、Al Petrofskyの
(let ((f (lambda (x) (x x)))) (let ((result1 (f call/cc))) (if (procedure? result1) (result1 1)) (let ((result2 (f call/cc))) (if (procedure? result2) (result2 2)) (list result1 result2)))) => (1 2)
が一番直感的に納得できる例だと思いました。JavaScript風に書き直せば、
function f (x) { return x(x);} var result1 = f(call/cc); if (is_procedure(result1)) { result1(1);} var result2 = f(call/cc); if (is_procedure(result2)) { result2(2);} document.write(result1); // => 1 document.write(result2); // => 2
call/ccの使用自体に副作用がなければ、同じ f(call/cc) の呼び出しの結果が違うことが説明できないということ。