2554 |
;;; |
;;; |
2555 |
|
|
2556 |
;; The inner `do' loop avoids re-establishing a catch every iteration, |
;; The inner `do' loop avoids re-establishing a catch every iteration, |
2557 |
;; that's only necessary if continue is actually used. |
;; that's only necessary if continue is actually used. A new key is |
2558 |
|
;; generated every time, so break and continue apply to their originating |
2559 |
|
;; `while' even when recursing. `while-helper' is an easy way to keep the |
2560 |
|
;; `key' binding away from the cond and body code. |
2561 |
;; |
;; |
2562 |
(define-macro (while cond . body) |
(define-macro (while cond . body) |
2563 |
(let ((key (make-symbol "while-key"))) |
(define (while-helper proc) |
2564 |
`(,do ((break ,(lambda () (throw key #t))) |
(do ((key (make-symbol "while-key"))) |
2565 |
(continue ,(lambda () (throw key #f)))) |
((catch key |
2566 |
((,catch (,quote ,key) |
(lambda () |
2567 |
(,lambda () |
(proc (lambda () (throw key #t)) |
2568 |
|
(lambda () (throw key #f)))) |
2569 |
|
(lambda (key arg) arg))))) |
2570 |
|
`(,while-helper (,lambda (break continue) |
2571 |
(,do () |
(,do () |
2572 |
((,not ,cond)) |
((,not ,cond)) |
2573 |
,@body) |
,@body) |
2574 |
#t) |
#t))) |
2575 |
,(lambda (key arg) arg)))))) |
|
2576 |
|
|
2577 |
|
|
2578 |
;;; {Module System Macros} |
;;; {Module System Macros} |