Skip to content

Instantly share code, notes, and snippets.

@valvallow
Created May 25, 2010 07:44
Show Gist options
  • Save valvallow/412895 to your computer and use it in GitHub Desktop.
Save valvallow/412895 to your computer and use it in GitHub Desktop.
update-if-true!, syntax, scheme
;; update-if-true!
(define-syntax cond-set!
(syntax-rules ()
((_ pred var init)
(if pred
(set! var init)))
((_ pred var1 init1 var2 init2 ...)
(if pred
(begin
(set! var1 init1)
(set! var2 init2) ...)))))
(define-syntax update-if-true!
(syntax-rules ()
((_ (pred var))
(let ((p pred))
(cond-set! p var p)))
((_ (pred1 var1)(pred2 var2) ...)
(begin
(update-if-true! (pred1 var1))
(update-if-true! (pred2 var2))
...))))
(define (test x y z)
(let ((x-is-big #f)
(y-is-zero #f)
(z-is-string #f))
(update-if-true!
((> x 5) x-is-big)
((zero? y) y-is-zero)
((string? z) z-is-string))
(values x-is-big y-is-zero z-is-string)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment