call/cc 入門 (Coroutine with call/cc) - MAYAHã®ååãèªãã§ã¿ãã
æ¼ç¿åé¡ã¿ãããªã®ããã£ãã®ã§ããã£ã¦ã¿ãã
gosh> (define cont #f) cont gosh> (and (call/cc (lambda (c) (begin (set! cont c) 10))) (begin (display 'a) 10)) a10 gosh> (cont 10) a10
(cont 10)ã®å®è¡ã§ãä½ãèµ·ãã¦ãã®ããªï¼
ãcall/cc ã®å¤ã x ã«ãã¦Î»æ½è±¡ããããã®ã§ãcontã¯
(lambda (x) (and x (begin (display 'a) 10)))
ã«ãªãããªããã¨ããã§ã
å®ã¯ãcontinuation ã¯ãcontinuation ãå¼ã°ããã¨ãcontinuation ãä½ããã call/cc ã®å¤ã«ãå¼æ°ã call/cc ã®è¿ãå¤ã¨ãã¦ã¸ã£ã³ããããã¨ããã®ãæ£ããæ¯ãèãã§ãã
call/cc 入門 (Coroutine with call/cc) - MAYAH
ã¨ãããã¨ããããã©ãããã«å¾ããªãã°ã
contãå¼ã°ããã¨ã(call/cc (lambda (c) (begin (set! cont c) 10)))ã®å¤ã«ã10ãcall/ccã®è¿ãå¤ã¨ãã¦ã¸ã£ã³ããã
ã¨ããå ·åã«ãªãã ã¤ã¾ãã
(and 10 (begin (display 'a) 10))
ã£ã¦ãã¨ã«ãªãã®ããªï¼
ãã£ã¦ã¿ããã
gosh> (and 10 (begin (display 'a) 10)) a10
ãããåãçµæã«ãªã£ãã
åãè¦é ã§ãæ®ãã®æ¼ç¿ããã£ã¦ã¿ãã
gosh> (define cont #f) cont gosh> (and (begin (display 'a) 10) (call/cc (lambda (c) (begin (set! cont c) 10)))) a10 gosh> (cont 10) 10 gosh> (begin (cont 10) (display 'c)) 10
ãã®å ´åãcontã¯
(lambda (x) (and (begin (display 'a) 10) x))
ã ããã(cont 10)ã¯
(and (begin (display 'a) 10) 10)
ã«ãªãã®ããªï¼å®è¡ãã¦ã¿ãã
gosh> (and (begin (display 'a) 10) 10) a10
ããï¼çµæãéãã
ããã£ã¡ãã(begin (cont 10) (display 'c))ã¯
gosh> (begin (and (begin (display 'a) 10) 10) (display 'c)) ac#<undef>
ããï¼ãããéãã
æå¾ã
gosh> (define cont #f) cont gosh> (begin (display 'a) (call/cc (lambda (c) (set! cont c) (display 'b))) (display 'c)) abc#<undef> gosh> (cont #f) c#<undef>
contã¯
(lambda (x) (begin (display 'a) x (display 'c)))
ã§ãå®è¡ãã¦ã¿ãã¨
gosh> (begin (display 'a) #f (display 'c)) ac#<undef>
ãããããããï¼ã¾ãéãã
ããä¸åå¼ç¨ãããã©ã
å®ã¯ãcontinuation ã¯ãcontinuation ãå¼ã°ããã¨ãcontinuation ãä½ããã call/cc ã®å¤ã«ãå¼æ°ã call/cc ã®è¿ãå¤ã¨ãã¦ã¸ã£ã³ããããã¨ããã®ãæ£ããæ¯ãèãã§ãã
ããããã½ãªãã ã¨æããã©ãããç解ã§ããªãã