This repository has been archived by the owner on Apr 29, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
narkisr
committed
Apr 27, 2012
1 parent
7c44c2b
commit 9cd67a7
Showing
6 changed files
with
40 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(ns com.narkisr.utils | ||
(:import java.lang.IllegalArgumentException)) | ||
|
||
; see http://tinyurl.com/d5kceu8 | ||
(defmacro do-template | ||
"Repeatedly evaluates template expr (in a do block) using values in | ||
args. args are grouped by the number of holes in the template. | ||
Example: (do-template (check _1 _2) :a :b :c :d) | ||
expands to (do (check :a :b) (check :c :d))" | ||
[expr & args] | ||
(when-not (template? expr) | ||
(throw (IllegalArgumentException. (str (pr-str expr) " is not a valid template.")))) | ||
(let [expr (walk/postwalk-replace {'_ '_1} expr) | ||
argcount (count (find-holes expr))] | ||
`(do ~@(map (fn [a] (apply-template expr a)) | ||
(partition argcount args))))) |