Created
May 31, 2013 14:10
-
-
Save AdamSaleh/5685224 to your computer and use it in GitHub Desktop.
Macro-ing contracts
This file contains 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
;lets say I have a constrained function like this: | |
(def constr-sqr | |
(contracts/with-constraints | |
sqr | |
(contracts/contract sqr-o "the only odd" | |
[n] [odd?]) | |
(contracts/contract sqr-c "the constraining of sqr" | |
[n] [number? (not= 0 n) => pos? number?]) | |
(contracts/contract sqr-s "only positive" | |
[n] [pos?]))) | |
; and I'd like to write a macro, that generates the contracts | |
(def constr-sqr | |
(contracts/with-constraints | |
sqr | |
(my-awesome-contract-macro ) | |
) | |
; but I can get macro outut only a single form ... | |
; and for example \w do | |
(def constr-sqr | |
(contracts/with-constraints | |
sqr | |
(do | |
(contracts/contract sqr-o "the only odd" | |
[n] [odd?]) | |
(contracts/contract sqr-c "the constraining of sqr" | |
[n] [number? (not= 0 n) => pos? number?]) | |
(contracts/contract sqr-s "only positive" | |
[n] [pos?])))) | |
; constraints notice only the last contract |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment