/
with.clj
31 lines (26 loc) · 1.07 KB
/
with.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns manners.with
"A namespace for defining the with-etiquette macro for scoped, etiquette
specific, manners."
(:require manners.victorian))
(defn- symbol->dynamic-partial [dynamic-var sym]
(let [func-sym (symbol (str 'manners.victorian \/ sym))
doc-string (str "Like a partial of manners."
func-sym
" to be used in with-etiquette so the etiquette"
" parameter is already defined.")]
`(defn ~sym
~doc-string
[value#] (~func-sym ~dynamic-var value#))))
(defmacro ^:private def-dynamic-partials
"Define partial versions of the given symbol"
[dynamic-var & symbols]
(let [defns (map (partial symbol->dynamic-partial dynamic-var) symbols)]
`(do ~@defns)))
;; A dynamic var to put the etiquette bound by with-etiquette in.
(declare ^:private ^:dynamic *etiquette*)
(def-dynamic-partials *etiquette* bad-manners rude? proper? avow)
(defmacro with-etiquette
"Start a scope with the given etiquettes as the base."
[etiquette & body]
`(binding [*etiquette* ~etiquette]
~@body))