drkcore

2009/09/25 21:31:48

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."}

Comments