Created
          August 1, 2012 14:43 
        
      - 
      
- 
        Save athos/3227434 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
    
  
  
    
  | (use 'syntactic-closure.core) | |
| (define-syntax aif | |
| (sc-macro-transformer | |
| (fn [[_ test then else] env] | |
| (quasiquote | |
| (let [it ~(make-syntactic-closure env nil test)] | |
| (if it | |
| ~(make-syntactic-closure env '[it] then) | |
| ~(make-syntactic-closure env nil else))))))) | |
| (define-syntax awhen | |
| (sc-macro-transformer | |
| (fn [[_ test & body] env] | |
| (quasiquote | |
| (aif ~(make-syntactic-closure env nil test) | |
| (do ~@(map #(make-syntactic-closure env '[it] %) body)) | |
| nil))))) | |
| (def m {:x "42"}) | |
| (aif (:x m) | |
| (Integer/parseInt it) | |
| 0) | |
| (awhen (:x m) | |
| (println "found x") | |
| (println it)) | |
| (macroexpand | |
| '(awhen (:x m) | |
| (println "found x") | |
| (println it))) | |
| ;=> | |
| (let* [it465 (:x user/m)] | |
| (if it465 | |
| (do | |
| (clojure.core/println "found x") | |
| (clojure.core/println it465)) | |
| nil)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment