Skip to content

Commit

Permalink
Move -> and ->> after resolve and add the ability to switch between -…
Browse files Browse the repository at this point in the history
…> and ->>. Need #262
  • Loading branch information
cgrand committed Feb 10, 2010
1 parent 2920f99 commit a91e805
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions src/clj/clojure/core.clj
Expand Up @@ -1121,37 +1121,6 @@
([x form] `(. ~x ~form))
([x form & more] `(.. (. ~x ~form) ~@more)))

(defmacro defthread-macro
[name docstring args & body]
(if (vector? docstring)
`(defthread-macro ~name nil ~docstring ~args ~@body)
(let [x (first args)
form (second args)]
`(defmacro ~name
~@(when docstring [docstring])
{:arglists '([~x] [~x ~form] [~x ~form & ~'more])}
([x#] x#)
([x# form#]
(let [form# (if (seq? form#) form# (list form#))
~x x#
~form form#]
(with-meta (do ~@body) (meta form#))))
([x# form# & more#] `(~'~name (~'~name ~x# ~form#) ~@more#))))))

(defthread-macro ->
"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
list already. If there are more forms, inserts the first form as the
second item in second form, etc."
[x form] (list* (first form) x (rest form)))

(defthread-macro ->>
"Threads the expr through the forms. Inserts x as the
last item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
last item in second form, etc."
[x form] (concat form [x]))

;;multimethods
(def global-hierarchy)

Expand Down Expand Up @@ -2753,8 +2722,8 @@
"Sequentially read and evaluate the set of forms contained in the
string"
[s]
(let [rdr (-> (java.io.StringReader. s)
(clojure.lang.LineNumberingPushbackReader.))]
(let [rdr (clojure.lang.LineNumberingPushbackReader.
(java.io.StringReader. s))]
(load-reader rdr)))

(defn set
Expand Down Expand Up @@ -2958,6 +2927,41 @@
([sym] (ns-resolve *ns* sym))
([env sym] (ns-resolve *ns* env sym)))

(defmacro defthread-macro
[name docstring args & body]
(if (vector? docstring)
`(defthread-macro ~name nil ~docstring ~args ~@body)
(let [x (first args)
form (second args)]
`(defmacro ~name
~@(when docstring [docstring])
{:arglists '([~x] [~x ~form] [~x ~form & ~'more])
:thread-op true}
([x#] x#)
([x# form#]
(let [form# (if (seq? form#) form# (list form#))
~x x#
~form form#]
(with-meta (do ~@body) (meta form#))))
([x# form# & more#]
(if (and (symbol? form#) (:thread-op (meta (resolve ~'&env form#))))
`(~form# ~x# ~@more#)
`(~'~name (~'~name ~x# ~form#) ~@more#)))))))

(defthread-macro ->
"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
list already. If there are more forms, inserts the first form as the
second item in second form, etc."
[x form] (list* (first form) x (rest form)))

(defthread-macro ->>
"Threads the expr through the forms. Inserts x as the
last item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
last item in second form, etc."
[x form] (concat form [x]))

(defn array-map
"Constructs an array-map."
([] (. clojure.lang.PersistentArrayMap EMPTY))
Expand Down

0 comments on commit a91e805

Please sign in to comment.