|
15 | 15 | [msg]
|
16 | 16 | (c/assertion-violation `throw-illegal-argument-exception "Illegal argument" msg))
|
17 | 17 |
|
| 18 | + |
| 19 | +(defn report-lens-deprecation [type] |
| 20 | + (println (str "active.clojure.record WARNING for record-type `" type |
| 21 | + "`: the explicit definition of lenses is deprecated in favor of regular " |
| 22 | + "accessors already being lenses"))) |
| 23 | + |
| 24 | + |
18 | 25 | ;; Only needed in ClojureScript, does nothing in Clojure
|
19 | 26 | (defn check-type
|
20 | 27 | [type rec]
|
|
158 | 165 | ?field-triples))))
|
159 | 166 | (declare ~@(map (fn [[?field ?accessor ?lens]] ?accessor) ?field-triples))
|
160 | 167 | ~@(mapcat (fn [[?field ?accessor ?lens]]
|
161 |
| - (let [?rec (with-meta `rec# {:tag ?type})] |
162 |
| - `((def ~(document-with-arglist ?accessor (vector ?type) (str "Access `" ?field "` field" |
163 |
| - (name-doc ?field) |
164 |
| - " from a [[" ?type "]] record. " ?docref)) |
165 |
| - (fn [~?rec] |
166 |
| - (check-type ~?type ~?rec) |
167 |
| - (. ~?rec ~(symbol (str "-" ?field))))) |
168 |
| - ~@(if ?lens |
169 |
| - (let [?data `data# |
170 |
| - ?v `v#] |
171 |
| - `((def ~(document ?lens (str "Lens for the `" ?field "` field" |
172 |
| - (name-doc ?field) |
173 |
| - " from a [[" ?type "]] record." ?docref)) |
174 |
| - (lens/lens ~?accessor |
175 |
| - (fn [~?data ~?v] |
176 |
| - (~?constructor ~@(map |
177 |
| - (fn [[?shove-field ?shove-accessor]] |
178 |
| - (if (= ?field ?shove-field) |
179 |
| - ?v |
180 |
| - `(~?shove-accessor ~?data))) |
181 |
| - ?field-triples))))))) |
182 |
| - '())))) |
| 168 | + (let [?rec (with-meta `rec# {:tag ?type}) |
| 169 | + ?data `data# |
| 170 | + ?v `v#] |
| 171 | + `((def ~(document-with-arglist |
| 172 | + ?accessor |
| 173 | + (vector ?type) |
| 174 | + (str "Lens for the `" ?field "` field" |
| 175 | + (name-doc ?field) |
| 176 | + " from a [[" ?type "]] record. " ?docref)) |
| 177 | + (lens/lens (fn [~?rec] |
| 178 | + (check-type ~?type ~?rec) |
| 179 | + (. ~?rec ~(symbol (str "-" ?field)))) |
| 180 | + (fn [~?data ~?v] |
| 181 | + (~?constructor ~@(map |
| 182 | + (fn [[?shove-field ?shove-accessor]] |
| 183 | + (if (= ?field ?shove-field) |
| 184 | + ?v |
| 185 | + `(~?shove-accessor ~?data))) |
| 186 | + ?field-triples))))) |
| 187 | + ~(when ?lens |
| 188 | + (report-lens-deprecation ?type) |
| 189 | + `(def ~?lens ~?accessor)) |
| 190 | + ))) |
183 | 191 | ?field-triples)))))
|
184 | 192 |
|
185 | 193 |
|
|
0 commit comments