This Web
Other Webs
Schematics
Scheme Links
3 <= x < 5
(and (<= 3 x) (< x 5))
x
(let ((x-val x)) (and (<= 3 x-val) (< x-val 5)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; chained comparisons syntax ;; example: (chain x < y <= z) roughly translates to ;; (and (< x y) (<= y z)), minus the duplicated ;; evaluation. (define-syntax chain (syntax-rules () ((_ x) x) ((_ x op y) (op x y)) ((_ x op y rest ...) (let ((y-val y)) (and (op x y-val) (chain y-val rest ...))))))
> (define (between-5-6? n) (chain 5 < n < 6)) > (between-5-6? 3) #f > (between-5-6? 5) #f > (between-5-6? 5.5) #t > (define (id* x) (display x) (newline) x) > (chain (id* 3) < (id* 4) > (id* 2)) 4 3 2 #t