minor updates
parent
eeaba0f7c3
commit
9a746eeac9
@ -0,0 +1,36 @@
|
|||||||
|
#lang racket/base
|
||||||
|
(require (for-syntax racket/base))
|
||||||
|
(provide (all-defined-out))
|
||||||
|
|
||||||
|
(define-syntax-rule (until COND EXPR ...)
|
||||||
|
(let loop ()
|
||||||
|
(unless COND
|
||||||
|
EXPR ...
|
||||||
|
(loop))))
|
||||||
|
|
||||||
|
(define-syntax-rule (while COND EXPR ...)
|
||||||
|
(let loop ()
|
||||||
|
(when COND
|
||||||
|
EXPR ...
|
||||||
|
(loop))))
|
||||||
|
|
||||||
|
(define-syntax (forever stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ . EXPRS)
|
||||||
|
;; todo: would be better with a syntax parameter
|
||||||
|
(with-syntax ([stop (datum->syntax #'EXPRS 'stop)])
|
||||||
|
#'(let/ec stop
|
||||||
|
(while #t
|
||||||
|
. EXPRS)))]))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(require rackunit)
|
||||||
|
(check-equal? (let ([x 5])
|
||||||
|
(until (zero? x)
|
||||||
|
(set! x (- x 1)))
|
||||||
|
x) 0)
|
||||||
|
(check-equal? (let ([x 5])
|
||||||
|
(while (positive? x)
|
||||||
|
(set! x (- x 1)))
|
||||||
|
x) 0))
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
#lang racket/base
|
|
||||||
(require (for-syntax racket/base))
|
|
||||||
(provide (all-defined-out))
|
|
||||||
|
|
||||||
(define-syntax-rule (until cond expr ...)
|
|
||||||
(let loop ()
|
|
||||||
(unless cond
|
|
||||||
expr ...
|
|
||||||
(loop))))
|
|
||||||
|
|
||||||
(define-syntax-rule (while cond expr ...)
|
|
||||||
(let loop ()
|
|
||||||
(when cond
|
|
||||||
expr ...
|
|
||||||
(loop))))
|
|
Loading…
Reference in New Issue