Subscribed unsubscribe Subscribe Subscribe

この前のやつのClojure版

(ns sample
  (:import (twitter4j Query
QueryResult
Tweet
Twitter
TwitterFactory)))

(def twitter-api (.. (TwitterFactory.) getInstance))

(defn make-query [word]
  (let [q (Query.)]
    (do (. q setQuery word)
q)))

(defn get-search-result [word]
  (let [q (make-query word)
res (. twitter-api search q)]
    (.getTweets res)))

(defn search-tweets [& word]
  (for [tweet (get-search-result (or (first word) "#clojure"))]
    (let [user (.getFromUser tweet)
text (.getText tweet)]
      (str "@" user ": " text))))

(defn search [& word]
  (println
   (reduce
    (fn [x y] (str x "\n" y)) (search-tweets (first word)))))

(search)

はてダのclojureの構文ハイライトいまいちだな。。。


Clojureの場合Javaの呼び出しが
いかにもJava呼んでます、みたいな感じ。
構文糖衣使ってもどうしても消えないような。