|
62 | 62 | (clout/route-compile ~route)
|
63 | 63 | ~route)))
|
64 | 64 |
|
65 |
| -(defn- assoc-&-binding [binds req sym] |
66 |
| - (assoc binds sym `(dissoc (:params ~req) |
67 |
| - ~@(map keyword (keys binds)) |
68 |
| - ~@(map str (keys binds))))) |
| 65 | +(defn- and-binding [req binds] |
| 66 | + `(dissoc (:params ~req) ~@(map keyword (keys binds)) ~@(map str (keys binds)))) |
69 | 67 |
|
70 |
| -(defn- assoc-symbol-binding [binds req sym] |
71 |
| - (assoc binds sym `(get-in ~req [:params ~(keyword sym)] |
72 |
| - (get-in ~req [:params ~(str sym)])))) |
| 68 | +(defn- symbol-binding [req sym] |
| 69 | + `(get-in ~req [:params ~(keyword sym)] (get-in ~req [:params ~(str sym)]))) |
| 70 | + |
| 71 | +(defn- application-binding [req sym func] |
| 72 | + `(~func ~(symbol-binding req sym))) |
73 | 73 |
|
74 | 74 | (defn- vector-bindings [args req]
|
75 | 75 | (loop [args args, binds {}]
|
76 |
| - (if-let [sym (first args)] |
77 |
| - (cond |
78 |
| - (= '& sym) |
79 |
| - (recur (nnext args) (assoc-&-binding binds req (second args))) |
80 |
| - (= :as sym) |
81 |
| - (recur (nnext args) (assoc binds (second args) req)) |
82 |
| - (symbol? sym) |
83 |
| - (recur (next args) (assoc-symbol-binding binds req sym)) |
84 |
| - :else |
85 |
| - (throw (Exception. (str "Unexpected binding: " sym)))) |
| 76 | + (if (first args) |
| 77 | + (let [[x y z] args] |
| 78 | + (cond |
| 79 | + (= '& x) |
| 80 | + (recur (nnext args) (assoc binds y (and-binding req binds))) |
| 81 | + (= :as x) |
| 82 | + (recur (nnext args) (assoc binds y req)) |
| 83 | + (and (symbol? x) (= :<< y) (nnext args)) |
| 84 | + (recur (drop 3 args) (assoc binds x (application-binding req x z))) |
| 85 | + (symbol? x) |
| 86 | + (recur (next args) (assoc binds x (symbol-binding req x))) |
| 87 | + :else |
| 88 | + (throw (Exception. (str "Unexpected binding: " x))))) |
86 | 89 | (mapcat identity binds))))
|
87 | 90 |
|
88 | 91 | (defn- warn-on-*-bindings! [bindings]
|
|
0 commit comments