Created
October 14, 2011 23:08
-
-
Save amalloy/1288628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn tricky-logic [x] | |
(cond (or (cheap-test1) | |
(expensive-test)) | |
(...body1...) | |
(and (cheap-test2) | |
(expensive-test)) | |
(...body2...) | |
:else (expensive-test))) | |
;; rewrite to avoid repeating tests *or* code: | |
(defn tricky-logic [x] | |
(let [expensive-results (delay (expensive-test))] | |
(cond (or (cheap-test1) | |
(force expensive-results)) | |
(...body1...) | |
(and (cheap-test2) | |
(force expensive-results)) | |
(...body2...) | |
:else (force expensive-results)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment