Created
          November 23, 2012 08:27 
        
      - 
      
- 
        Save CampingScorpion/4134522 to your computer and use it in GitHub Desktop. 
    doseq-indexed
  
        
  
    
      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
    
  
  
    
  | ;; Example: | |
| ;; (doseq-indexed idx [name names] | |
| ;; (println (str idx ". " name) | |
| (defmacro doseq-indexed [index-sym [item-sym coll] & body] | |
| `(let [idx-atom# (atom 0)] | |
| (doseq [~item-sym ~coll] | |
| (let [~index-sym (deref idx-atom#)] | |
| ~@body | |
| (swap! idx-atom# inc))))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
A live version of this gist: http://blog.klipse.tech/clojure/2016/05/09/macro-tutorial-4.html