Add a new syntax macro, compose-if.
The macro resembles (or x (fn x)) except: 1) The value is only evaluated once, and 2) Multiple (single-argument) functions can be chained. If the original value or the result of any function is #f, the final value is #f. Otherwise the result is ((compose ,@fns) x). Short-circuit evaluation is employed.
This commit is contained in:
parent
173c117d86
commit
704c473015
|
|
@ -69,4 +69,10 @@
|
||||||
(define-syntax (let/cc var . body)
|
(define-syntax (let/cc var . body)
|
||||||
`(call/cc (lambda (,var) ,@body)))
|
`(call/cc (lambda (,var) ,@body)))
|
||||||
|
|
||||||
|
(define-syntax (compose-if x fn . fns)
|
||||||
|
(let ([it (gensym)])
|
||||||
|
(if (pair? fns)
|
||||||
|
`(let ([,it ,x]) (if ,it (compose-if (,fn ,it) ,@fns) #f))
|
||||||
|
`(let ([,it ,x]) (if ,it (,fn ,it) #f)))))
|
||||||
|
|
||||||
; vim:set syntax=scheme sw=2 expandtab:
|
; vim:set syntax=scheme sw=2 expandtab:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue