【发布时间】:2014-08-02 16:36:05
【问题描述】:
我已经开始学习clojure了。我被困在 ->> 宏中使用 let
代码是:
(defn make-summary [wordStr]
;// split string into words
(let [words (clojure.string/split wordStr #"[\[\]\(\),.\s+]")
;// convert words to lowercase.
lowerCaseWords (map clojure.string/lower-case words)]
;// remove stop words
(->> (remove-stop-words lowerCaseWords)
;// count the frequency of words
;// ---------- HERE IS THE PROBLEM ------------------------------
(let [totalWords (count )] ;// <--- HOW TO MAKE MACRO PUT THE THING HERE ???
(count-frequency)
;// sort on the basis of frequency
(sort #(> (get %1 1) (get %2 1)))
;// find the keywords
)
)))
我被困在 defn 函数中的第二个let。
我该如何编码?
【问题讨论】:
-
你不能那样做。 ->> 将参数作为表单的最后一项插入。它不会进入表单并在任意位置插入内容。为什么你仍然需要第二个 let,你会在哪里使用 totalWords?
-
顺便说一句,您可能想使用
frequencies。 -
如果你真的想使用 let in a ->> 或者需要在不同位置的参数,那么你可以使用 as->
-
@kima 你能解释更多吗..这就是我要找的
标签: clojure