Hell Is Around the Corner / Tricky

ダビーでスモーキー。

ProductName Maxinquaye
Tricky
Island / ¥ 1,357 (1995-04-18)
在庫あり。

trickyは最初のほうのアルバムのほうが好き。レゲエはあんま好きじゃないけどdubは好きってのが割と謎(自分七不思議のひとつ)。

Programming Clojure chapter 5

どんどん読む。5章はfunctional programmingに関して。遅延評価についてもふれている。

ProductName Programming Clojure (Pragmatic Programmers)
Stuart Halloway
Pragmatic Bookshelf / ¥ 3,198 ()
在庫あり。

clojureは(jvmが?)末尾最適化しないので、tail recursionでなくself recursionをすべし。

self recursionはrecurを使う。またはlazy-seqをつかって遅延評価させる。

mutual recursionの場合はtrampolineという最適化テクニックを使うとよいらしい(未消化)。

Programming Clojure chapter 4

4章はsequenceという抽象の話がメイン。

ProductName Programming Clojure (Pragmatic Programmers)
Stuart Halloway
Pragmatic Bookshelf / ¥ 3,198 ()
在庫あり。

clojureではsequenceの操作関数は重要。若干関数リファレンスみたいになってしまっている部分もあるが、それは仕方ない。どうせ、実際にコード書くときに何度も見返すことになるので、lispとか触ったことがあれば軽く読み流せる章。

Programming Clojure chapter 3

3章はJava周りと最適化の話

ProductName Programming Clojure (Pragmatic Programmers)
Stuart Halloway
Pragmatic Bookshelf / ¥ 3,198 ()
在庫あり。

Syntactic Sugar

javaのメソッドを呼ぶための使いやすい構文糖衣が用意されている/(slash)と.(dot)が重要

Collection

ClojureのCollectionはconcurrency-safeらしい。

Lancet

Clojureのビルドツール。これは使ってみないと読んだだけではよくわからん。

たらい回し関数

jrubyのたらい回し関数のエントリみてたらClojureでもやってみたくなった。

Clojure 1.0.0-
user=> (defn tak [x y z] 
      (if (>= y x) 
      z 
      (tak (tak (- x 1) y z) (tak (- y 1) z x) (tak (- z 1) x y))))
#'user/tak
user=> (time (dotimes [_ 100] (tak 24 16 8)))
"Elapsed time: 27580.504 msecs"
nil

ついでにOCamlでも

let rec tak x y z =
  if y >= x then z
  else tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y)
;;

for a = 1 to 100 do
  ignore(tak 24 16 8)
done
;;

まずはバイトコードで。

$ ocamlc tak.ml -o tak.exe
$ time ./tak.exe 

real    0m10.777s
user    0m10.692s
sys     0m0.033s

ネイティブコードにコンパイルすると

$ ocamlopt tak.ml -o tak_opt.exe
$time ./tak_opt.exe 

real    0m1.130s
user    0m1.119s
sys     0m0.006s

結構はやい。

そういえばMooseでLispはたらい回し関数はしるくらいまではやっとこうと思いつつ止まってしまっていたのに今気づいた。

Single [Photek Remix] / everything but the girl

photekのremixが渋過ぎ。

ProductName Like the Deserts Miss the Rain
Everything But the Girl
Virgin / ¥ 1,357 (2003-03-11)
在庫あり。

Ni-Ten-Ichi-Ryu

ProductName Ni-Ten-Ichi-Ryu
Photek
Virgin / ¥ 590 (1997-02-24)


否、お前だけだ。

Cowgirl / Underworld

Dubnobasswithmyheadmanの中ではCowgirlが一番好きかな。

ProductName Dubnobasswithmyheadman
Underworld
Junior Boys Own / ?円 ( 1998-05-11 )


Programming Clojure chapter 2

2章はClojureの基本的な説明。

ProductName Programming Clojure (Pragmatic Programmers)
Stuart Halloway
Pragmatic Bookshelf / ¥ 3,198 ()
在庫あり。

キーワードは関数として使える。

user=> (defstruct book :title :author)
#'user/book
user=> (def b (struct book "Programming Clojure" "Stuart Halloway"))
#'user/b
user=> (b :title)
"Programming Clojure"

これは以下のようにキーワードが先にきても良い。

user=> (:title b)
"Programming Clojure"

namespacesの変更

(in-ns name)

meta-data

^が使える。

user=> ^#'str
{:ns #<Namespace clojure.core>, :name str, :file "clojure/core.clj",
 :line 322, :arglists ([] [x] [x & ys]), :tag java.lang.String,
 :doc "With no args, returns the empty string. With one arg x, 
 returns\n  x.toString().  (str nil) returns the empty string.
 With more than\n  one arg, returns the concatenation of the str 
 values of the args."}

clojureでフィボナッチ

遅延評価つかうとこんなに簡単

(def fibs (lazy-cat [0 1]   (map + fibs (rest fibs))))

みてみる

user=> (take 20 fibs)
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181)

Portishead

ドープな揺らぎに身を委ねる。ダウナーだけど堕ちすぎず、コントロールできる範囲で留まれる。

1stのWandering Starが最高ですな。

ProductName Dummy
Portishead
Go! Discs/London / ¥ 1,357 (1994-10-17)
在庫あり。

ProductName Portishead
Portishead
Universal / ¥ 1,357 (1997-09-30)
在庫あり。

ProductName Third
Portishead
ISLAND / ¥ 1,357 (2008-04-28)
在庫あり。