Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clojureの基礎 〜マクロ編〜

Clojureの基礎 〜マクロ編〜

2016/6/11 プログラミング言語基礎勉強会のLT発表資料です。

OHTA Shogo

June 11, 2016
Tweet

More Decks by OHTA Shogo

Other Decks in Programming

Transcript

  1. $PNQPKVSF ‣ $MPKVSFͷϧʔςΟϯάϥΠϒϥϦ (defroutes app-routes (GET “/” [] (index)) (GET

    “/en” [] (index)) (GET “/fr” [] (index-fr)) (GET “/:greeting” [greeting] (view greeting)))
  2. DPSFNBUDI ‣ ύλʔϯϚονϥΠϒϥϦ (match inst [:mov z x] (recur (subst

    z x) insts) [:add z x y] (recur (do-op + z x y) insts) [:sub z x y] (recur (do-op - z x y) insts) [:push z x] (recur (push z x) insts) [:pop z] (recur (pop z) insts) [:jnz l] (if (:flag env) [l env] (recur env insts)) [:jz l] (if (:flag env) (recur env insts) [l env] …)
  3. DPSFUZQFE ‣ ੩తܕνΣοΫϥΠϒϥϦ (ann new-file [(U URI String) -> File])

    (defn new-file [s] (if (string? s) (File. ^String s) (File. ^URI s)))
  4. DPSFBTZOD ‣ νϟωϧϕʔεͷඇಉظϓϩάϥϛϯάϥΠϒϥϦ (go (while true (let [v (<! ch)]

    (println v)))) (go (loop [i 0] (>! ch i) (recur (inc i)))) ड৴ଆίʔυ ૹ৴ଆίʔυ
  5. HPDMPKVSF (doseq [[l n] (frequencies (map #(count (str %)) (keys

    (ns-publics ’clojure.core))))] (printf “%2d %s\n” l (apply str (repeat n \*)))) ΦϦδφϧͷίʔυ
  6. HPDMPKVSF (doseq [[l n] (frequencies (map #(count (str %)) (keys

    (ns-publics ’clojure.core))))] (printf “%2d %s\n” l (apply str (repeat n \*)))) (goclojure (dq [[l n] (qs (mp #(ou (sr %)) (ks (nsb ’clojure.core))))] (pf “%2d %s\n” l (ay sr (rep n \*)))) ΦϦδφϧͷίʔυ HPDMPKVSFΛ࢖ͬͯॻ͖׵͑ͨίʔυ