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
;; ever | |
(define-syntax ever | |
(syntax-rules () | |
((_ ((var init) ...) body ...) | |
(let ((var init) ...) | |
(let ((next (call/cc identity))) | |
body ... | |
(next next)))) | |
((_ body ...) | |
(ever () body ...)))) | |
(let/cc hop | |
(ever ((n 10)) | |
(if (zero? n) | |
(hop n) | |
(begin | |
(print n) | |
(set! n (- n 1)))))) | |
;; 10 | |
;; 9 | |
;; 8 | |
;; 7 | |
;; 6 | |
;; 5 | |
;; 4 | |
;; 3 | |
;; 2 | |
;; 1 | |
;; 0 |
until を書き直してみます。
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
(define-syntax until | |
(syntax-rules () | |
((_ label ((var init) ...) body ...) | |
(let/cc label | |
(ever ((var init) ...) | |
body ...))) | |
((_ label body ...) | |
(until label () body ...)))) | |
(let ((n 10)) | |
(until break | |
(if (zero? n) | |
(break n) | |
(print (* n (set! n (- n 1))))))) | |
;; 90 | |
;; 72 | |
;; 56 | |
;; 42 | |
;; 30 | |
;; 20 | |
;; 12 | |
;; 6 | |
;; 2 | |
;; 0 | |
;; 0 | |
0 件のコメント:
コメントを投稿