diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 6fa139d..58d0fb4 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1479,6 +1479,14 @@ ([x form] `(. ~x ~form)) ([x form & more] `(.. (. ~x ~form) ~@more))) +(defn- thread-form [x form thread-fn] + (if-not (seq? form) + (list form x) + (if (= () form) + (list x) + (with-meta (thread-fn x form) + (meta form))))) + (defmacro -> "Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a @@ -1486,9 +1494,8 @@ second item in second form, etc." {:added "1.0"} ([x] x) - ([x form] (if (seq? form) - (with-meta `(~(first form) ~x ~@(next form)) (meta form)) - (list form x))) + ([x form] (thread-form x form (fn [x form] + (list* (first form) x (next form))))) ([x form & more] `(-> (-> ~x ~form) ~@more))) (defmacro ->> @@ -1497,9 +1504,7 @@ list already. If there are more forms, inserts the first form as the last item in second form, etc." {:added "1.1"} - ([x form] (if (seq? form) - (with-meta `(~(first form) ~@(next form) ~x) (meta form)) - (list form x))) + ([x form] (thread-form x form (fn [x form] (concat form [x])))) ([x form & more] `(->> (->> ~x ~form) ~@more))) ;;multimethods