Created
May 24, 2010 22:36
syntax, ever, 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
;; 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 |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment