Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 88e487551c
Fetching contributors…

Cannot retrieve contributors at this time

27 lines (23 sloc) 0.967 kB
(ns serializable.fn
"Serializable functions! Check it out."
(:refer-clojure :exclude [fn])
(:import java.io.Writer))
(defn- save-env [bindings form]
(let [form (with-meta (cons `fn (rest form)) ; serializable/fn, not core/fn
(meta form))
quoted-form `(quote ~form)]
(if bindings
`(list `let ~(vec (apply concat (for [b bindings
:let [sym (.sym b)]]
[`(quote ~sym)
`(list `quote ~sym)])))
~quoted-form)
quoted-form)))
(defmacro ^{:doc (str (:doc (meta #'clojure.core/fn))
"\n\n Oh, but it also allows serialization!!!111eleven")}
fn [& sigs]
`(with-meta (clojure.core/fn ~@sigs)
{:type ::serializable-fn
::source ~(save-env (vals &env) &form)}))
(defmethod print-method ::serializable-fn [o ^Writer w]
(print-method (::source (meta o)) w))
Jump to Line
Something went wrong with that request. Please try again.