diff options
author | Rich Hickey <richhickey@gmail.com> | 2010-05-20 13:14:56 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2010-05-20 13:14:56 -0400 |
commit | 4651e60808bb459355a3a5d0d649c4697c672e28 (patch) | |
tree | 1ee14210937a3f379fcdfaa8edb03399b57c25db | |
parent | df8b048ab34751256e193e277d92f5a5bc1b53cd (diff) |
don't append numbers on top-level fn class names
-rw-r--r-- | src/clj/clojure/core.clj | 196 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 23 |
2 files changed, 114 insertions, 105 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index cb17f492..70d83348 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -273,7 +273,8 @@ (if (if (clojure.lang.Util/equiv 'fn ifn) (if (instance? clojure.lang.Symbol iname) false true)) ;; inserts the same fn name to the inline fn if it does not have one - (assoc m :inline (cons ifn (cons name (next inline)))) + (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName name) "__inliner")) + (next inline)))) m)) m (conj (if (meta name) (meta name) {}) m)] (list 'def (with-meta name m) @@ -767,21 +768,22 @@ [x] (. clojure.lang.Numbers (inc x))) ;; reduce is defined again later after InternalReduce loads -(defn reduce - ([f coll] - (let [s (seq coll)] - (if s - (reduce f (first s) (next s)) - (f)))) - ([f val coll] - (let [s (seq coll)] - (if s - (if (chunked-seq? s) - (recur f - (.reduce (chunk-first s) f val) - (chunk-next s)) - (recur f (f val (first s)) (next s))) - val)))) +(def reduce + (fn r + ([f coll] + (let [s (seq coll)] + (if s + (r f (first s) (next s)) + (f)))) + ([f val coll] + (let [s (seq coll)] + (if s + (if (chunked-seq? s) + (recur f + (.reduce (chunk-first s) f val) + (chunk-next s)) + (recur f (f val (first s)) (next s))) + val))))) (defn reverse "Returns a seq of the items in coll in reverse order. Not lazy." @@ -2505,7 +2507,7 @@ ~@body (recur (unchecked-inc ~i))))))) -(defn into +#_(defn into "Returns a new coll consisting of to-coll with all of the items of from-coll conjoined." {:added "1.0"} @@ -2515,6 +2517,87 @@ (recur (conj ret (first items)) (next items)) ret))) +;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn transient + "Alpha - subject to change. + Returns a new, transient version of the collection, in constant time." + {:added "1.1"} + [^clojure.lang.IEditableCollection coll] + (.asTransient coll)) + +(defn persistent! + "Alpha - subject to change. + Returns a new, persistent version of the transient collection, in + constant time. The transient collection cannot be used after this + call, any such use will throw an exception." + {:added "1.1"} + [^clojure.lang.ITransientCollection coll] + (.persistent coll)) + +(defn conj! + "Alpha - subject to change. + Adds x to the transient collection, and return coll. The 'addition' + may happen at different 'places' depending on the concrete type." + {:added "1.1"} + [^clojure.lang.ITransientCollection coll x] + (.conj coll x)) + +(defn assoc! + "Alpha - subject to change. + When applied to a transient map, adds mapping of key(s) to + val(s). When applied to a transient vector, sets the val at index. + Note - index must be <= (count vector). Returns coll." + {:added "1.1"} + ([^clojure.lang.ITransientAssociative coll key val] (.assoc coll key val)) + ([^clojure.lang.ITransientAssociative coll key val & kvs] + (let [ret (.assoc coll key val)] + (if kvs + (recur ret (first kvs) (second kvs) (nnext kvs)) + ret)))) + +(defn dissoc! + "Alpha - subject to change. + Returns a transient map that doesn't contain a mapping for key(s)." + {:added "1.1"} + ([^clojure.lang.ITransientMap map key] (.without map key)) + ([^clojure.lang.ITransientMap map key & ks] + (let [ret (.without map key)] + (if ks + (recur ret (first ks) (next ks)) + ret)))) + +(defn pop! + "Alpha - subject to change. + Removes the last item from a transient vector. If + the collection is empty, throws an exception. Returns coll" + {:added "1.1"} + [^clojure.lang.ITransientVector coll] + (.pop coll)) + +(defn disj! + "Alpha - subject to change. + disj[oin]. Returns a transient set of the same (hashed/sorted) type, that + does not contain key(s)." + {:added "1.1"} + ([set] set) + ([^clojure.lang.ITransientSet set key] + (. set (disjoin key))) + ([set key & ks] + (let [ret (disj set key)] + (if ks + (recur ret (first ks) (next ks)) + ret)))) + +;redef into with batch support +(defn into + "Returns a new coll consisting of to-coll with all of the items of + from-coll conjoined." + {:added "1.0"} + [to from] + (if (instance? clojure.lang.IEditableCollection to) + (persistent! (reduce conj! (transient to) from)) + (reduce conj to from))) + (defmacro import "import-list => (package-symbol class-name-symbols*) @@ -5397,86 +5480,7 @@ {:added "1.1"} [promise val] (promise val)) -;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn transient - "Alpha - subject to change. - Returns a new, transient version of the collection, in constant time." - {:added "1.1"} - [^clojure.lang.IEditableCollection coll] - (.asTransient coll)) - -(defn persistent! - "Alpha - subject to change. - Returns a new, persistent version of the transient collection, in - constant time. The transient collection cannot be used after this - call, any such use will throw an exception." - {:added "1.1"} - [^clojure.lang.ITransientCollection coll] - (.persistent coll)) - -(defn conj! - "Alpha - subject to change. - Adds x to the transient collection, and return coll. The 'addition' - may happen at different 'places' depending on the concrete type." - {:added "1.1"} - [^clojure.lang.ITransientCollection coll x] - (.conj coll x)) - -(defn assoc! - "Alpha - subject to change. - When applied to a transient map, adds mapping of key(s) to - val(s). When applied to a transient vector, sets the val at index. - Note - index must be <= (count vector). Returns coll." - {:added "1.1"} - ([^clojure.lang.ITransientAssociative coll key val] (.assoc coll key val)) - ([^clojure.lang.ITransientAssociative coll key val & kvs] - (let [ret (.assoc coll key val)] - (if kvs - (recur ret (first kvs) (second kvs) (nnext kvs)) - ret)))) - -(defn dissoc! - "Alpha - subject to change. - Returns a transient map that doesn't contain a mapping for key(s)." - {:added "1.1"} - ([^clojure.lang.ITransientMap map key] (.without map key)) - ([^clojure.lang.ITransientMap map key & ks] - (let [ret (.without map key)] - (if ks - (recur ret (first ks) (next ks)) - ret)))) -(defn pop! - "Alpha - subject to change. - Removes the last item from a transient vector. If - the collection is empty, throws an exception. Returns coll" - {:added "1.1"} - [^clojure.lang.ITransientVector coll] - (.pop coll)) - -(defn disj! - "Alpha - subject to change. - disj[oin]. Returns a transient set of the same (hashed/sorted) type, that - does not contain key(s)." - {:added "1.1"} - ([set] set) - ([^clojure.lang.ITransientSet set key] - (. set (disjoin key))) - ([set key & ks] - (let [ret (disj set key)] - (if ks - (recur ret (first ks) (next ks)) - ret)))) - -;redef into with batch support -(defn into - "Returns a new coll consisting of to-coll with all of the items of - from-coll conjoined." - {:added "1.0"} - [to from] - (if (instance? clojure.lang.IEditableCollection to) - (persistent! (reduce conj! (transient to) from)) - (reduce conj to from))) (defn flatten "Takes any nested combination of sequential things (lists, vectors, diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index 6aceb282..8ce076d4 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -3078,9 +3078,11 @@ static public class FnExpr extends ObjExpr{ (munge(currentNS().name.name) + "$"); if(RT.second(form) instanceof Symbol) name = ((Symbol) RT.second(form)).name; - String simpleName = ((name != null ? - munge(name).replace(".", "_DOT_") : "fn") - + "__" + RT.nextID()); + String simpleName = name != null ? + (munge(name).replace(".", "_DOT_") + + (enclosingMethod != null ? "__" + RT.nextID() : "")) + : ("fn" + + "__" + RT.nextID()); fn.name = basename + simpleName; fn.internalName = fn.name.replace('.', '/'); fn.objtype = Type.getObjectType(fn.internalName); @@ -3898,9 +3900,9 @@ static public class ObjExpr implements Expr{ if(compiledClass == null) try { - if(RT.booleanCast(COMPILE_FILES.deref())) - compiledClass = RT.classForName(name);//loader.defineClass(name, bytecode); - else +// if(RT.booleanCast(COMPILE_FILES.deref())) +// compiledClass = RT.classForName(name);//loader.defineClass(name, bytecode); +// else { loader = (DynamicClassLoader) LOADER.deref(); compiledClass = loader.defineClass(name, bytecode, src); @@ -5338,7 +5340,8 @@ public static Object eval(Object form, boolean freshLoader) throws Exception{ && !(RT.first(form) instanceof Symbol && ((Symbol) RT.first(form)).name.startsWith("def"))) { - ObjExpr fexpr = (ObjExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), "eval"); + ObjExpr fexpr = (ObjExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), + "eval" + RT.nextID()); IFn fn = (IFn) fexpr.eval(); return fn.invoke(); } @@ -5829,7 +5832,9 @@ static void compile1(GeneratorAdapter gen, ObjExpr objx, Object form) throws Exc if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) line = (Integer) RT.meta(form).valAt(RT.LINE_KEY); Var.pushThreadBindings( - RT.map(LINE, line)); + RT.map(LINE, line + ,LOADER, RT.makeClassLoader() + )); try { form = macroexpand(form); @@ -5879,7 +5884,7 @@ public static Object compile(Reader rdr, String sourcePath, String sourceName) t CONSTANT_IDS, new IdentityHashMap(), KEYWORDS, PersistentHashMap.EMPTY, VARS, PersistentHashMap.EMPTY - ,LOADER, RT.makeClassLoader() + // ,LOADER, RT.makeClassLoader() )); try |