Skip to content

Commit

Permalink
Change extend-tagged-value to hygenic macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglook committed May 14, 2014
1 parent d908b5a commit 84639db
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/puget/data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,17 @@

(defmacro extend-tagged-value
"Extends the TaggedValue protocol with implementations which return the
given symbol as the tag and use the body to calculate the value. The symbol
'this' is bound to the data. This macro also defines a print-method which
given symbol as the tag and use the given expression to calculate the value.
The expression should resolve to a function which accepts one argument and
returns the serialized value. This macro also defines a print-method which
delegates to edn-str."
[t tag expr]
`(do
`(let [value-fn# ~expr]
(extend-type ~t
TaggedValue
(edn-tag [~'this] ~tag)
(edn-value [~'this]
~(if (or (symbol? expr) (keyword? expr))
(list expr 'this)
expr)))
(edn-tag [this#] ~tag)
(edn-value [this#]
(value-fn# this#)))
(defprint-method ~t)))


Expand All @@ -143,7 +142,8 @@

(defmacro extend-tagged-map
[c tag]
`(extend-tagged-value ~c ~tag (into {} (seq ~'this))))
`(extend-tagged-value ~c ~tag
(comp (partial into {}) seq)))



Expand All @@ -169,7 +169,7 @@
; #bin - Binary data in the form of byte arrays.
(extend-tagged-value
(class (byte-array 0)) 'bin
(->> this b64/encode (map char) (apply str)))
#(->> % b64/encode (map char) (apply str)))


(defn read-bin
Expand Down

0 comments on commit 84639db

Please sign in to comment.