Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bind over more than just constant expressions.

  • Loading branch information...
commit 989521d82c1fd7672490d18d6e0b9dd8d3336d70 1 parent 73b9b97
@technomancy authored
View
3  .gitignore
@@ -1,4 +1,5 @@
pom.xml
*jar
lib
-classes
+classes
+/.lein-failures
View
6 project.clj
@@ -1,7 +1,5 @@
-(defproject serializable-fn "1.1.0"
+(defproject serializable-fn "1.1.1"
:url "http://github.com/technomancy/serializable-fn"
:author "Seajure"
:description "Make functions that have pretty representations."
- :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
- [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]]
- :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]])
+ :dependencies [[org.clojure/clojure "1.2.1"]])
View
10 src/serializable/fn.clj
@@ -2,10 +2,10 @@
"Serializable functions! Check it out."
(:refer-clojure :exclude [fn]))
-(defn- save-env [env form]
- (if env
- `(let ~(vec (flatten (for [[name local] env]
- [name (.v (.init local))])))
+(defn- save-env [bindings form]
+ (if bindings
+ `(let ~(vec (apply concat (for [b bindings]
+ [(.sym b) (.eval (.init b))])))
(~@form))
form))
@@ -14,7 +14,7 @@
fn [& sigs]
`(with-meta (clojure.core/fn ~@sigs)
{:type ::serializable-fn
- ::source (quote ~(save-env &env &form))}))
+ ::source (quote ~(save-env (vals &env) &form))}))
(defmethod print-method ::serializable-fn [o ^Writer w]
(print-method (::source (meta o)) w))
View
9 test/serializable/fn_test.clj
@@ -1,7 +1,7 @@
(ns serializable.fn-test
(:refer-clojure :exclude [fn])
- (:use [serializable.fn] :reload-all)
- (:use [clojure.test]))
+ (:use [serializable.fn]
+ [clojure.test]))
(def dinc-list '(fn [x] (inc (inc x))))
@@ -29,5 +29,6 @@
(is (= 2 ((eval (read-string (pr-str dinc))) 0))))
(deftest serializable-roundtrip-with-lexical-context
- (let [x 0]
- (is (= 2 ((eval (read-string (pr-str (fn [] (dinc x))))))))))
+ (let [x 0, y (+ 95 4)]
+ (is (= [2 100]
+ ((eval (read-string (pr-str (fn [] [(dinc x) (inc y)])))))))))
Please sign in to comment.
Something went wrong with that request. Please try again.