『プログラミングClojure』第1版第1刷は Clojure v1.0 〜 1.1 あたり書かれているため動かないコードがあるので、1.4 で動く様に書き換えるメモ。
(Clojure1.4, MacOSX10.8)
- Clojure - home
- Overview - Clojure v1.6 API documentation
- stuarthalloway/programming-clojure at first-edition · GitHub
2.3関数
p39
(defn indexable-word? [word] (> (count word) 2)) ;; (require ['clojure.string :as 'str]) (require ['clojure.string :as 'str :only 'split]) (filter indexable-word? (str/split "A fine day it is" #"\W+")) (filter (fn [w] (> (count w) 2)) (str/split "A fine day" #"\W+")) (defn indexable-words [text] (let [indexable-word? (fn [w] (> (count w) 2))] (filter indexable-word? (str/split "A fine day it is" #"\W+")))) (indexable-words "a fine day it is")
2.4 var、束縛、名前空間
p 44
追記:20130118
(require ['clojure.string :as 'str :only ('split 'join)]) (defn ellipsize [words] (let [[w1 w2 w3] (str/split words #"\s+")] (str/join " " [w1 w2 w3 "..."]))) (ellipsize "The quick brown fox jumps over the lazy dog.")
以下あとで書く予定