diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-10-11 16:28:54 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-10-11 16:28:54 +0000 |
commit | 3b3e540c03f726486ff5712354bc0a9796e7d570 (patch) | |
tree | 40b494463ef307143f96a5e02d483dcdca931dac | |
parent | 46e50142c1a101b800e3f19bfff611c53ef820c9 (diff) |
enhanced print/read - default print-method prints
#=(classname. "toString() result")
changed #'x back to (var x) always
#=(var x) print/read support
-rw-r--r-- | src/clj/clojure/boot.clj | 41 | ||||
-rw-r--r-- | src/jvm/clojure/lang/LispReader.java | 18 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Var.java | 2 |
3 files changed, 44 insertions, 17 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj index 0abcc356..4e33578c 100644 --- a/src/clj/clojure/boot.clj +++ b/src/clj/clojure/boot.clj @@ -3425,10 +3425,32 @@ (defmethod print-method nil [o, #^Writer w] (.write w "nil")) +(defn print-ctor [o print-args #^Writer w] + (.write w "#=(") + (.write w (.getName (class o))) + (.write w ". ") + (print-args o w) + (.write w ")")) + (defmethod print-method :default [o, #^Writer w] + (print-ctor o #(print-method (str %1) %2) w)) + +(defmethod print-method clojure.lang.Keyword [o, #^Writer w] + (.write w (str o))) + +(defmethod print-method Number [o, #^Writer w] + (.write w (str o))) + +(defn print-simple [o, #^Writer w] (print-meta o w) (.write w (str o))) +(defmethod print-method clojure.lang.Symbol [o, #^Writer w] + (print-simple o w)) + +(defmethod print-method clojure.lang.Var [o, #^Writer w] + (print-simple o w)) + (defmethod print-method clojure.lang.ISeq [o, #^Writer w] (print-meta o w) (print-sequential "(" print-method " " ")" o w)) @@ -3439,18 +3461,12 @@ (prefer-method print-method clojure.lang.IPersistentList clojure.lang.ISeq) -(defn print-ctor [o print-args #^Writer w] - (.write w "#=(") - (.write w (.getName (class o))) - (.write w ". ") - (print-args o w) - (.write w ")")) -(defmethod print-method java.util.List [o, #^Writer w] +(defmethod print-method java.util.Collection [o, #^Writer w] (print-ctor o #(print-sequential "[" print-method " " "]" %1 %2) w)) -(prefer-method print-method clojure.lang.IPersistentList java.util.List) -(prefer-method print-method clojure.lang.IPersistentVector java.util.List) +(prefer-method print-method clojure.lang.IPersistentList java.util.Collection) +(prefer-method print-method clojure.lang.IPersistentVector java.util.Collection) (def #^{:tag String :doc "Returns escape string for char or nil if none"} @@ -3511,6 +3527,13 @@ (print-meta s w) (print-sequential "#{" print-method " " "}" (seq s) w)) +(defmethod print-method java.util.Set [s, #^Writer w] + (print-ctor s + #(print-sequential "#{" print-method " " "}" (seq %1) %2) + w)) + +(prefer-method print-method clojure.lang.IPersistentSet java.util.Set) + (def #^{:tag String :doc "Returns name string for char or nil if none"} char-name-string diff --git a/src/jvm/clojure/lang/LispReader.java b/src/jvm/clojure/lang/LispReader.java index c0cd63ec..702eea0c 100644 --- a/src/jvm/clojure/lang/LispReader.java +++ b/src/jvm/clojure/lang/LispReader.java @@ -459,12 +459,12 @@ static class VarReader extends AFn{ public Object invoke(Object reader, Object quote) throws Exception{
PushbackReader r = (PushbackReader) reader;
Object o = read(r, true, null, true);
- if(o instanceof Symbol)
- {
- Object v = Compiler.maybeResolveIn(Compiler.currentNS(), (Symbol) o);
- if(v instanceof Var)
- return v;
- }
+// if(o instanceof Symbol)
+// {
+// Object v = Compiler.maybeResolveIn(Compiler.currentNS(), (Symbol) o);
+// if(v instanceof Var)
+// return v;
+// }
return RT.list(THE_VAR, o);
}
}
@@ -861,6 +861,10 @@ static class EvalReader extends AFn{ else if(o instanceof IPersistentList)
{
Symbol fs = (Symbol) RT.first(o);
+ if(fs.equals(THE_VAR))
+ {
+ return Compiler.resolve((Symbol) RT.second(o));
+ }
if(fs.name.endsWith("."))
{
Object[] args = RT.toArray(RT.rest(o));
@@ -876,7 +880,7 @@ static class EvalReader extends AFn{ {
return ((IFn) v).applyTo(RT.rest(o));
}
- throw new Exception("Can't resolve " + v);
+ throw new Exception("Can't resolve " + fs);
}
else
throw new IllegalArgumentException("Unsupported #= form");
diff --git a/src/jvm/clojure/lang/Var.java b/src/jvm/clojure/lang/Var.java index fcbd746f..a84ff663 100644 --- a/src/jvm/clojure/lang/Var.java +++ b/src/jvm/clojure/lang/Var.java @@ -72,7 +72,7 @@ public static Var intern(Namespace ns, Symbol sym, Object root, boolean replaceR public String toString(){ if(ns != null) - return "#'" + ns.name + "/" + sym; + return "#=(var " + ns.name + "/" + sym + ")"; return "#<Var: " + (sym != null ? sym.toString() : "--unnamed--") + ">"; } |