<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3707366315089692807</id><updated>2024-09-07T11:24:20.366+09:00</updated><category term="Scala"/><category term="Scalaz"/><category term="Clojure"/><category term="ClojureScript"/><category term="LWJGL"/><category term="ゲーム"/><category term="JavaFX"/><category term="Coq"/><category term="Python"/><category term="Emacs"/><category term="Haskell"/><category term="Play"/><category term="Ruby"/><category term="Unfiltered"/><category term="Zipper"/><category term="お知らせ"/><title type='text'>ひなたねこ</title><subtitle type='html'>自由気ままにプログラミングについて記録していくBlogです。</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>81</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-4713331180629864656</id><published>2013-05-12T19:05:00.000+09:00</published><updated>2013-05-12T19:05:11.087+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><title type='text'>ぼくのかんがえたさいきょうのMonad Syntax in Clojure</title><content type='html'>Gistに書きました。
&lt;script src=&quot;https://gist.github.com/halcat0x15a/5562947.js&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/4713331180629864656/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2013/05/monad-syntax-in-clojure.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/4713331180629864656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/4713331180629864656'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2013/05/monad-syntax-in-clojure.html' title='ぼくのかんがえたさいきょうのMonad Syntax in Clojure'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-805926060735784826</id><published>2013-04-13T15:23:00.000+09:00</published><updated>2013-04-13T15:24:13.545+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Haskell"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><title type='text'>ScalaでChurch encoding</title><content type='html'>data Maybe a = Nothing | Just a&lt;br /&gt;
という型をekmettさんのコードを参考にChurch encodingしてみると、&lt;br /&gt;
&lt;br /&gt;
newtype Maybe { runMaybe :: forall r. a -&amp;gt; r -&amp;gt; r -&amp;gt; r }&lt;br /&gt;
&lt;br /&gt;
となります。（多分）&lt;br /&gt;
&lt;br /&gt;
これをScalaで表現してみました。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/5376994.js&quot;&gt;&lt;/script&gt;

とても面倒なことになってますが、ちゃんとMaybeモナドとして動作します。&lt;br /&gt;
Haskellだと結構綺麗に書けたりします。 &lt;br /&gt;
&lt;br /&gt;
Church encodingすると大抵の場合に高速化されます。&lt;br /&gt;
このMaybeモナドの例では、emptyをbindで合成した時に、Justの場合の処理を破棄しています。 &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://d.hatena.ne.jp/syamino/20120524/p1&quot;&gt;ラムダ計算で代数的データ型を表現する方法&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
この記事も面白いのでぜひ読んでみて下さい。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/805926060735784826/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2013/04/scalachurch-encoding.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/805926060735784826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/805926060735784826'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2013/04/scalachurch-encoding.html' title='ScalaでChurch encoding'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-497995243092060438</id><published>2013-03-01T18:02:00.002+09:00</published><updated>2013-03-01T18:02:48.028+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="Zipper"/><title type='text'>clojure.zipを使ったHistoryの表現</title><content type='html'>&lt;h2&gt;
&lt;a href=&quot;https://gist.github.com/halcat0x15a/5063351&quot;&gt;from gist&lt;/a&gt;
&lt;/h2&gt;
&lt;br&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/5063351.js&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/497995243092060438/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2013/03/clojureziphistory.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/497995243092060438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/497995243092060438'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2013/03/clojureziphistory.html' title='clojure.zipを使ったHistoryの表現'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-7059058059269087342</id><published>2013-02-07T13:17:00.002+09:00</published><updated>2013-02-07T13:17:25.490+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><title type='text'>Destructuringを使おう</title><content type='html'>Clojureで積極的にDestructuringを使っていこうという話です。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
ListやVectorに対する再帰&lt;/h3&gt;
&lt;br /&gt;
例: index-of&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=index_of1.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Destructuringを使うとこんな感じで書ける。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=index_of2.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
firstとrestがなくなりました。 &lt;br /&gt;
&lt;br /&gt;
例: end&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=end1.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Destructuringは関数の引数部に直接書ける。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=end2.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
リスト全体を束縛する変数を省略出来ました。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
MapやRecordに対するDestructuring&lt;/h3&gt;
&lt;br /&gt;
レコードに対する操作&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=complex.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
例: abs&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=abs1.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Destructuringを使うとこんな感じ。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=abs2.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
{:keys [foo bar ...]}はフィールドを列挙することでその値を束縛します。&lt;br /&gt;
&lt;br /&gt;
例: add &lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=add1.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
フィールドと違った名前の変数名を付ける場合は{foo&#39; :foo bar&#39; :bar ...}という記法が使えます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/halcat0x15a/4728434.js?file=add2.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Destructuringを使うことで要素の取得、束縛を簡素にしませんか？</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/7059058059269087342/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2013/02/destructuring.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/7059058059269087342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/7059058059269087342'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2013/02/destructuring.html' title='Destructuringを使おう'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-2619341377692873025</id><published>2013-02-02T12:20:00.000+09:00</published><updated>2013-02-02T12:20:51.761+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><title type='text'>Clojureで継承みたいなナニカ</title><content type='html'>Clojureのdeftypeやdefrecordではinterfaceのみを実装することができます。&lt;br /&gt;
しかし、継承のように実装があるclassを継承したいときがあります。&lt;br /&gt;
&lt;br /&gt;例えばこんなコードがあります。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4695995.js?file=sequence.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
ConsとNilのaddとemptyの実装が同じです。&lt;br /&gt;
共通化したい。&lt;br /&gt;
&lt;br /&gt;
とりあえず、addとemptyを別Protocolに。 &lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4695995.js?file=adder.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
ListというProtocolを作って、それに対するAdderを定義します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4695995.js?file=list.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
ConsとNilに対してListを実装すれば、めでたしめでたし。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4695995.js?file=cons.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/2619341377692873025/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2013/02/clojure.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/2619341377692873025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/2619341377692873025'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2013/02/clojure.html' title='Clojureで継承みたいなナニカ'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-5256458713744337742</id><published>2013-01-29T14:01:00.000+09:00</published><updated>2013-01-29T14:07:33.633+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><title type='text'>ClojureのKeywordはLensなのですy</title><content type='html'>&lt;i&gt;春休みヤッター！&lt;/i&gt;&lt;br /&gt;
ブログの更新頻度も上げていくつもりです。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Lens&lt;/h3&gt;
&lt;br /&gt;
Lensはあるフィールドに対するgetterとsetterを持つ。&lt;br /&gt;
コードにするとこんな感じ。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=lens.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=lget.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
見てわかるとおり、lgetはgetで、lsetはassocで十分なのだ。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=getassoc.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;
Lensの特徴&lt;/h3&gt;
&lt;br /&gt;
getとsetがあればmodifyが定義できる。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=modify.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=modifynumer.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Clojureにはupdate-inがある。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=updatein.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Lensは合成が可能だ。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=compose.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=composenumerdenom.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Clojureの{get, assoc, update}-in関数は複数のKeywordをとることで、ネストしたレコードに対しても有効です。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=getin.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
LensはStateモナドと組み合わせると素敵です。&lt;br /&gt;
更新途中の状態を取得することは出来ないけれど、Clojureにはアローマクロが存在します。 &lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=arrow.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4661916.js?file=add.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
KeywordがLensだということを意識すれば、Lensの考え方を応用することが出来ますね。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/5256458713744337742/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2013/01/clojurekeywordlensy.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5256458713744337742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5256458713744337742'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2013/01/clojurekeywordlensy.html' title='ClojureのKeywordはLensなのですy'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-5854949235696946446</id><published>2012-12-21T00:31:00.000+09:00</published><updated>2012-12-21T00:31:39.695+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Konst</title><content type='html'>この記事は&lt;a href=&quot;http://partake.in/events/7211abc9-ebb8-4670-b912-3089dc5e0edd&quot;&gt;Scalaz Advent Calendar&lt;/a&gt;の20日目の記事です。&lt;br /&gt;
&lt;br /&gt;
ScalaにはFunction.constという常に一定の値を返す関数があります。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4336158.js?file=const.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
この関数を型レベルで表したものがScalazにKonstとして定義されています。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Konst&lt;/h3&gt;
&lt;br /&gt;
NaturalTransformationを例にKonstを使ってみます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4336158.js?file=konst.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
あまり使わなさそうですね！&lt;br /&gt;
私としてはまだScalaz6にあったPartialApplyの方が便利な気がするのですが。&lt;br /&gt;
まあ、型推論がうまくいかなかったり、Unapplyが新しく入ったりしたことが原因にあるのでしょうね。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/5854949235696946446/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/konst.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5854949235696946446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5854949235696946446'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/konst.html' title='Konst'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-104431534524347652</id><published>2012-12-18T00:35:00.000+09:00</published><updated>2012-12-18T00:35:00.050+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Scalazのかきかた</title><content type='html'>&lt;blockquote class=&quot;twitter-tweet&quot; data-in-reply-to=&quot;280445003149496320&quot; lang=&quot;ja&quot;&gt;
@&lt;a href=&quot;https://twitter.com/halcat0x15a&quot;&gt;halcat0x15a&lt;/a&gt; あれ(´・ω・｀)？じゃあsyntaxの説明記事お願いします！&lt;br /&gt;
— Kenji Yoshidaさん (@xuwei_k) &lt;a data-datetime=&quot;2012-12-16T22:55:42+00:00&quot; href=&quot;https://twitter.com/xuwei_k/status/280446131773784064&quot;&gt;12月 16, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;async&quot; charset=&quot;utf-8&quot; src=&quot;//platform.twitter.com/widgets.js&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
というわけで、&lt;a href=&quot;http://partake.in/events/7211abc9-ebb8-4670-b912-3089dc5e0edd&quot;&gt;Scalaz Advent Calendar&lt;/a&gt;の18日目の記事です。&lt;br /&gt;
&lt;br /&gt;
Scalazには多くの型クラスとそのインスタンスが定義されており、それを扱うために、多くの記法が存在します。&lt;br /&gt;
この記事では簡単で冗長な記法から、複雑で簡素な記法まで紹介していきます。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
インスタンスの取得&lt;/h3&gt;
&lt;br /&gt;
implicit valueとして定義されている型クラスのインスタンスは、implicit parameterにより取得が可能です。&lt;br /&gt;
&lt;br /&gt;
そのインスタンスの取得にも様々方法があります。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;implicitly&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Scala標準ライブラリに定義されている、implicit valueを取得する関数です。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=implicitly.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;b&gt;TypeClass&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
また、Scalazの型クラスにはインスタンスの取得のための関数、TypeClass.applyを使用することができます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=apply.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;
関数呼び出し&lt;/h3&gt;
&lt;br /&gt;
ある型クラスの関数を使用するとき、先ほどのようにインスタンスから直接呼び出すことができます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=join.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;b&gt;Ops&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
しかし、明示的に型クラスのインスタンスを取得するのは冗長です。&lt;br /&gt;
Scalazではimplicit conversionを用いて、型クラスのインスタンスをもつオブジェクトに対して暗黙の型変換を提供します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=ops.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
暗黙型変換の他にも、単一のオブジェクトを対象としない型クラスの関数がインポートされます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=zero.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;
関数定義&lt;/h3&gt;
&lt;br /&gt;
関数を定義するとき、implicit parameterを指定する方法が２つあります。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;implicit&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1つはimplicitを使う方法です。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=double.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;b&gt;Context Bounds&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
もう1つ、Context Boundsというものが存在します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=contextbounds.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
インスタンスを明示的に扱わない場合はContex Boundsで定義した方が良いでしょう。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=contextboundsops.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;
Syntax&lt;/h3&gt;
&lt;br /&gt;
大抵の場合の場合はOpsとContex Boundsで短いコードが得られますが、これらを使っても冗長になる場合があります。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=morph.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
Scalaでは返り値の型を指定してもimplicit valueを決定することは出来ないので明示的に型を書く必要があります。&lt;br /&gt;
このような場合、Syntaxを使うことで明示的に型を指定する必要がなくなります。 &lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4319080.js?file=syntax.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;
まとめ&lt;/h3&gt;
&lt;br /&gt;
短く簡素なコードになるほど、複雑な仕組みが使われていきます。&lt;br /&gt;
大抵のものはContex BoundsとOpsで短いコードになるので、積極的に使っていきましょう。&lt;br /&gt;
型クラスのインスタンスから直接関数を呼ぶのも良いですが、Syntaxをimportした方が簡素になる場合があることも頭に入れておくと良いでしょう。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/104431534524347652/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/scalaz.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/104431534524347652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/104431534524347652'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/scalaz.html' title='Scalazのかきかた'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-7410568818660969093</id><published>2012-12-17T13:01:00.000+09:00</published><updated>2012-12-17T13:01:54.491+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaFX"/><title type='text'>JavaFX &amp; Web Start with Clojure</title><content type='html'>This article is the 5th of &lt;a href=&quot;http://atnd.org/events/33874&quot;&gt;JavaFX Advent Calendar&lt;/a&gt; and a sequel of &lt;a href=&quot;http://basking-cat.blogspot.jp/2012/12/clojure.html&quot;&gt;Tic-tac-toe with Clojure&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://halcat0x15a.github.com/tic-tac-toe/&quot;&gt;Tic-tac-toe&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Since the logic of the game have been made, we only need to implement at the drawing.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Application&lt;/h3&gt;
&lt;br /&gt;
As the basis for JavaFX, inherit &lt;i&gt;javafx.application.Application&lt;/i&gt; to the main class.&lt;br /&gt;
&lt;br /&gt;
In order to compile the class files of Java, we use the &lt;i&gt;gen-class&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=ns.clj&quot;&gt;&lt;/script&gt;

In the &lt;i&gt;main&lt;/i&gt; method calls &lt;i&gt;Application.launch&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=main.clj&quot;&gt;&lt;/script&gt;

In the &lt;i&gt;start&lt;/i&gt; method implements &lt;i&gt;tic-tac-toe.game.Canvas&lt;/i&gt; and register the handler in each panel.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=start.clj&quot;&gt;&lt;/script&gt;

&lt;i&gt;doto&lt;/i&gt; is useful when using the GUI library in Clojure.&lt;br /&gt;
We can run continuously some methods under the instance.&lt;br /&gt;
It is like the &lt;i&gt;instance_eval&lt;/i&gt; in Ruby.&lt;br /&gt;
&lt;br /&gt;
Such an interface as &lt;i&gt;EventHandler&lt;/i&gt; is obtained an instance by using &lt;i&gt;reify&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Web Start&lt;/h3&gt;
&lt;br /&gt;
First, make a standalone jar file with &lt;i&gt;lein2 uberjar&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Then create a jnlp file.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=jnlp.xml&quot;&gt;&lt;/script&gt;

The all-permissions are needed to run Clojure.&lt;br /&gt;
&lt;br /&gt;
We must make a signature, because it requires all-permissions.&lt;br /&gt;
&lt;br /&gt;
You can make the keystore by &lt;i&gt;keytool&lt;/i&gt;, and sign the jar using &lt;i&gt;jarsigner&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;keytool -genkey -keystore foo -alias bar
jarsigner -keystore foo target/tic-tac-toe-0.1.0-SNAPSHOT-standalone.jar bar
&lt;/pre&gt;
&lt;br /&gt;
You can start with Web Start.&lt;br /&gt;
&lt;br /&gt;
If you try on local environment, rewrite the codebase of jnlp file.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Miscellaneous Thoughts&lt;/h3&gt;
&lt;br /&gt;
I think that JavaFX is simpler than Swing and we would be able to write the GUI application easily.&lt;br /&gt;
&lt;br /&gt;
But I felt that the Web Start is not suitable for other required language runtime, such as the Scala and Clojure.&lt;br /&gt;
Because file size becomes very large.</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/7410568818660969093/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/javafx-web-start-with-clojure.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/7410568818660969093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/7410568818660969093'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/javafx-web-start-with-clojure.html' title='JavaFX &amp; Web Start with Clojure'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-1710300280144224416</id><published>2012-12-15T22:21:00.000+09:00</published><updated>2012-12-15T22:22:37.681+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>UndoT</title><content type='html'>この記事は&lt;a href=&quot;http://partake.in/events/7211abc9-ebb8-4670-b912-3089dc5e0edd&quot;&gt;Scalaz Advent Calendar&lt;/a&gt;の15日目の記事です。 &lt;br /&gt;
&lt;br /&gt;
scalazのcoreのjarに含まれ、独自のパッケージが存在しながらも、全く話題に上がらないundoについて書きます。&lt;br /&gt;
&lt;br /&gt;
scalaz.undo以下にはUndoTとHistoryの2つのデータ型があります。&lt;br /&gt;
&lt;br /&gt;
UndoはHistoryを状態とするStateモナドで、Historyはundo, redoの為のListと、currentのデータを持ちます。&lt;br /&gt;
&lt;br /&gt;
例を作ってみます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4292161.js&quot;&gt;&lt;/script&gt;

この時、Historyはこのように変遷しています。&lt;br /&gt;
&lt;br /&gt;
History(&quot;initialize&quot;, Nil, Nil) // eval(&quot;initialize&quot;)&lt;br /&gt;
History(&quot;hello&quot;, List(&quot;initialize&quot;), Nil) // hput(&quot;hello&quot;)&lt;br /&gt;
History(&quot;world&quot;, List(&quot;hello&quot;, &quot;initialize&quot;), Nil) // hput(&quot;world&quot;)&lt;br /&gt;
History(&quot;hello&quot;, List(&quot;initialize&quot;), List(&quot;world&quot;)) // undo&lt;br /&gt;
History(&quot;world&quot;, List(&quot;hello&quot;, &quot;initialize&quot;), Nil) // redo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
これを使っているユーザーがどれだけいるのか気になるところです。&lt;br /&gt;
&lt;br /&gt;
これだけでは物足りないと思ったので、MonadStateについて書こうと思いましたが、UndoTのMonadStateのインスタンスの定義が&lt;a href=&quot;https://github.com/scalaz/scalaz/blob/10598b015f5574d8ebb0ca862892355f0414661f/core/src/main/scala/scalaz/undo/UndoT.scala#L131&quot;&gt;おかしい&lt;/a&gt;気がする。&lt;br /&gt;
&lt;br /&gt;
なので今日は&lt;a href=&quot;https://github.com/scalaz/scalaz/pull/224&quot;&gt;pull request&lt;/a&gt;を投げて終わります。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/1710300280144224416/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/undot.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/1710300280144224416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/1710300280144224416'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/undot.html' title='UndoT'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-4030048045896864693</id><published>2012-12-13T20:54:00.002+09:00</published><updated>2012-12-13T21:05:16.504+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Codensity</title><content type='html'>この記事は&lt;a href=&quot;http://partake.in/events/7211abc9-ebb8-4670-b912-3089dc5e0edd&quot;&gt;Scalaz Advent Calendar&lt;/a&gt;の13日目の記事です。&lt;br /&gt;
&lt;br /&gt;
Codensityについてググると、&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://blog.sigfpe.com/2008/12/mother-of-all-monads.html&quot;&gt;The Mother of all Monads&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
という記事が見つかる。&lt;br /&gt;
Codensityは継続モナドとほぼ同じものみたい。&lt;br /&gt;
&lt;br /&gt;
この記事にある例をScalaで書いてみる。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4257293.js?file=i.scala&quot;&gt;&lt;/script&gt;

Option&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4257293.js?file=option.scala&quot;&gt;&lt;/script&gt;

Disjunction&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4257293.js?file=disj.scala&quot;&gt;&lt;/script&gt;

なるほど。&lt;br /&gt;
CodensityがOptionやDisjunctionとして動く。&lt;br /&gt;
&lt;br /&gt;
でもこれってIdTじゃ(ry&lt;br /&gt;
&lt;br /&gt;
Codensityは継続モナドのようなもの、ということで継続らしい例を書いてみる。&lt;br /&gt;
&lt;br /&gt;
iprintで、計算の経過を表示する。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4257293.js?file=iprint.scala&quot;&gt;&lt;/script&gt;

Some(bar)とNoneが表示される。&lt;br /&gt;
&lt;br /&gt;
継続を破棄するbreakを定義し、for式で使ってみる。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4257293.js?file=break.scala&quot;&gt;&lt;/script&gt;

Some(bar)だけが表示される。&lt;br /&gt;
&lt;br /&gt;
無事、計算が破棄された。&lt;br /&gt;
&lt;br /&gt;
Codensityはあるモナドにおいて計算量を減らせることがわかった。&lt;br /&gt;
他にも何か出来そうだが、わたしが思いついたのはこれくらい。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/4030048045896864693/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/condensity.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/4030048045896864693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/4030048045896864693'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/condensity.html' title='Codensity'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-3225648427175849679</id><published>2012-12-09T19:15:00.000+09:00</published><updated>2012-12-09T19:15:05.793+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Injectiveを考える</title><content type='html'>この記事は&lt;a href=&quot;http://partake.in/events/7211abc9-ebb8-4670-b912-3089dc5e0edd&quot;&gt;Scalaz Advent Calendar&lt;/a&gt;の9日目の記事です。&lt;br /&gt;
&lt;br /&gt;
この記事に書いてあることは役にたたないと思うので、あまり気合を入れて読まないでください。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Injective&lt;/h3&gt;
&lt;br /&gt;
Scalazには、Injectively, Injective1 ~ Injective5が定義されている。&lt;br /&gt;
よくわからない。&lt;br /&gt;
&lt;br /&gt;
Injectiveをググってみると、どうやら単射のことっぽい。&lt;br /&gt;
&lt;br /&gt;
Injectiveは型パラメータをとる型を型引数にとる。&lt;br /&gt;
つまり、種(カインド)が* -&amp;gt; *や、* -&amp;gt; * -&amp;gt; *である型が単射であるいう制約をつけるものではないかと考えた。&lt;br /&gt;
&lt;br /&gt;
とりあえずInjectiveの例を列挙してみる。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;List&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4244105.js?file=list.scala&quot;&gt;&lt;/script&gt;

ふつうに定義できる。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;type member&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Hoge#Fは未定義なので、インスタンスの供給は出来ない。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4244105.js?file=member.scala&quot;&gt;&lt;/script&gt;

&lt;b&gt;dependent method types&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4244105.js?file=depend.scala&quot;&gt;&lt;/script&gt;

明示的にインスタンスを渡す必要はあるが、コンパイルすることは可能。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ふむ、よくわからない。&lt;br /&gt;
&lt;br /&gt;
単射にならない型がもしあるのだとしたら、F[_]に対して、ある型Aを渡した時にコンパイルが通らないということだろうか。&lt;br /&gt;
ということは、F[_]がとりうる型に対して制約をかければよいということだろう。&lt;br /&gt;
&lt;br /&gt;
次のような例を書いた。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4244105.js?file=injective.scala&quot;&gt;&lt;/script&gt;

なるほど。&lt;br /&gt;
確かに、単射ではないからInjectiveのインスタンスが定義出来ない。&lt;br /&gt;
&lt;br /&gt;
Injectiveの意味がようやく理解できた。&lt;br /&gt;
&lt;br /&gt;
InjectiveはLiskovのコードで使われているが、まあ、よくわからない。&lt;br /&gt;
わからなくても、この先困るということもないと思う。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/3225648427175849679/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/injective.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/3225648427175849679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/3225648427175849679'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/injective.html' title='Injectiveを考える'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-8821797267087169418</id><published>2012-12-05T20:24:00.002+09:00</published><updated>2012-12-05T20:27:52.282+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaFX"/><title type='text'>ClojureでJavaFX &amp; Web Start</title><content type='html'>&lt;a href=&quot;http://atnd.org/events/33874&quot;&gt;JavaFX Advent Calendar 2012&lt;/a&gt;&lt;br /&gt;
5日目の記事です。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://halcat0x15a.github.com/tic-tac-toe/&quot;&gt;三目並べ&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://basking-cat.blogspot.jp/2012/12/clojure.html&quot;&gt;Cojureで三目並べ&lt;/a&gt;の続き。&lt;br /&gt;
&lt;br /&gt;
ここでは三目並べのJavaFX実装について書きます。&lt;br /&gt;
&lt;br /&gt;
ゲームのロジックは作ってあるのであとは描画のところを実装するだけ。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Application&lt;/h3&gt;
&lt;br /&gt;
JavaFXの基本として、メインクラスにjavafx.application.Applicationを継承します。&lt;br /&gt;
&lt;br /&gt;
ここではgen-classを使って、Javaのclassファイルにコンパイルします。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=ns.clj&quot;&gt;&lt;/script&gt;

mainメソッドではApplication.launchを呼び出します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=main.clj&quot;&gt;&lt;/script&gt;

あとはstartメソッドでtic-tac-toe.game.Canvasを実装し、各パネルにhandlerを登録します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=start.clj&quot;&gt;&lt;/script&gt;

ClojureでGUIライブラリを使うときに便利なのがdoto。&lt;br /&gt;
あるインスタンスのもとで、メソッドを連続して実行することが出来ます。&lt;br /&gt;
Rubyのinstance_evalのようなものですね。&lt;br /&gt;
&lt;br /&gt;
EventHandlerなどのインターフェースはreifyを使うことで実体を得られます。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Web Start&lt;/h3&gt;
&lt;br /&gt;
JavaFX Script時代にはいくつかWeb Startのアプリケーションを作ったことが&lt;br /&gt;
ありましたが、JavaFX 2になってからは初のWeb Startです。&lt;br /&gt;
&lt;br /&gt;
まずは、lein2 uberjarでstandaloneなjarを作ります。&lt;br /&gt;
20MBもあるのはClojure+JavaFXのclassファイルが入ってる所為です。&lt;br /&gt;
&lt;br /&gt;
次にjnlpですが、こんな感じになりました。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4200332.js?file=jnlp.xml&quot;&gt;&lt;/script&gt;

all-permissionsになっているのはClojureを実行するためです。&lt;br /&gt;
多分JRubyやGroovyでもall-permissionsが必要になるはず。&lt;br /&gt;
&lt;br /&gt;
all-permissionsを要求するので、署名をしなければなりません。&lt;br /&gt;
keytoolで適当なkeystoreを作ります。&lt;br /&gt;
&lt;br /&gt;
keytool -genkey -keystore foo -alias bar&lt;br /&gt;
&lt;br /&gt;
fooというファイルが作られるので、jarsignerを使ってjarに署名します。&lt;br /&gt;
&lt;br /&gt;
jarsigner -keystore foo target/tic-tac-toe-0.1.0-SNAPSHOT-standalone.jar bar&lt;br /&gt;
&lt;br /&gt;
これでWeb Startで起動できます。&lt;br /&gt;
実際に試す場合はjnlpファイルのcodebaseを&lt;br /&gt;
&lt;br /&gt;
codebase=&quot;file:/home/halcat0x15a/tic-tac-toe/&quot;&lt;br /&gt;
&lt;br /&gt;
のように書き替え、&lt;br /&gt;
&lt;br /&gt;
javaws tic_tac_toe.jnlp&lt;br /&gt;
&lt;br /&gt;
で実行可能です。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
雑感&lt;/h3&gt;
&lt;br /&gt;
このプログラムではたいしたことをしていませんが、JavaFXのおかげで、Swingよりもシンプルで簡単にGUIを書けるようになったと思います。&lt;br /&gt;
他のGUIライブラリと比べても、ライブラリの設計は格段に良くなったと感じます。&lt;br /&gt;
&lt;br /&gt;
Web Startは、ScalaやClojureなどのランタイムが他に必要な言語にはあまりむかないのかなと感じました。&lt;br /&gt;
プログラム+ライブラリ+ランタイムとなると、かなりファイルサイズが大きくなってしまいます。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/8821797267087169418/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/clojurejavafx-web-start.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/8821797267087169418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/8821797267087169418'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/clojurejavafx-web-start.html' title='ClojureでJavaFX &amp; Web Start'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-7070713004425944489</id><published>2012-12-05T20:24:00.001+09:00</published><updated>2012-12-05T20:25:15.632+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="ClojureScript"/><title type='text'>ClojureScriptでgoog.graphics</title><content type='html'>&lt;a href=&quot;http://partake.in/events/17085fbb-501f-4a78-a4cd-ec6a34484a60&quot;&gt;altjs Advent Calendar 2012&lt;/a&gt;&lt;br /&gt;
5日目の記事です。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://halcat0x15a.github.com/tic-tac-toe/&quot;&gt;三目並べ&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://basking-cat.blogspot.jp/2012/12/clojure.html&quot;&gt;Cojureで三目並べ&lt;/a&gt;の続き。&lt;br /&gt;
&lt;br /&gt;
ここでは三目並べのClojureScriptによる実装について書きます。&lt;br /&gt;
&lt;br /&gt;
ゲームのロジックは作ってあるのであとは描画のところを実装するだけ。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
goog.graphics&lt;/h3&gt;
&lt;br /&gt;
描画にはgoog.graphicsを使うことにします。&lt;br /&gt;
&lt;br /&gt;
ClojureScriptはGoogle Closure Libraryで実装されており、nsでJavaScriptのライブラリをrequireすることが出来ます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4201879.js?file=ns.clj&quot;&gt;&lt;/script&gt;

各種定数。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4201879.js?file=const.clj&quot;&gt;&lt;/script&gt;

tic-tac-toe.game.Canvasを実装します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4201879.js?file=canvas.clj&quot;&gt;&lt;/script&gt;

main関数を定義します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4201879.js?file=main.clj&quot;&gt;&lt;/script&gt;

HTMLはコンパイルされたJavaScriptを読み込み、main関数を呼び出します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4201879.js?file=index.html&quot;&gt;&lt;/script&gt;

これで動いてほしいところですが、cljs.core.logicがバグってるので、コンパイルされた.jsの修正が必要です。&lt;br /&gt;
cljs.core.logic.macros._take_STAR_のところをcljs.core.logic._take_STAR_に変更します。&lt;br /&gt;
&lt;br /&gt;
masterでは直ってますが、修正版がpublishされていないのが悲しいですね。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
雑感&lt;/h3&gt;
&lt;br /&gt;
いままでもClojureScriptについていろいろ書いてますが、やはりClojureは書いてて楽しいです。&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
最近はprotocolとrecordとmacroが好みです。&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
論理プログラミングで書いたコードがWeb上で動いているのはなかなかおもしろいと思うのですが、コンパイルされたJavaScriptのコードをみるとものすごくカオスです。&lt;br /&gt;
&lt;br /&gt;
Google Closure Compilerによるアシストがあるとはいえ、ファイルサイズは比較的大きくなるので、注意です。&lt;br /&gt;
&lt;br /&gt;
cljsbuildのおかげで、今回のようなJVMとWebの両方で動くようなコードが書けるので、これからClojureScriptを使う人には是非知ってもらいたいものです。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/7070713004425944489/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/clojurescriptgooggraphics.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/7070713004425944489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/7070713004425944489'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/clojurescriptgooggraphics.html' title='ClojureScriptでgoog.graphics'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-8121892142188642530</id><published>2012-12-05T20:24:00.000+09:00</published><updated>2012-12-05T20:29:06.013+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="ClojureScript"/><title type='text'>Clojureで三目並べ</title><content type='html'>&lt;a href=&quot;http://qiita.com/advent-calendar/2012/lisp/participants&quot;&gt;Lisp Advent Calendar 2012&lt;/a&gt;&lt;br /&gt;
6日目の記事です。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://halcat0x15a.github.com/tic-tac-toe/&quot;&gt;三目並べ&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
ここでは三目並べソルバについて書きます。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
tic tac toe&lt;/h3&gt;
&lt;br /&gt;
三目並べ、すなわち◯×ゲームです。&lt;br /&gt;
小学生の頃とかやってました。&lt;br /&gt;
このゲームは両者が最善を尽せば必ず引分けになるゲームで、その最善手もわかりやすいので他人とやってもだいたいドローになります。&lt;br /&gt;
&lt;br /&gt;
この三目並べで盤面から次の手を返すプログラムを、ClojureとClojureScriptの両方で動くように作成します。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
core.logic&lt;/h3&gt;
&lt;br /&gt;
今回は論理プログラミングでこのパズルを解きます。&lt;br /&gt;
&lt;br /&gt;
最初にnamespaceですが、ClojureとClojureScriptの両方で動かす為に、多少の黒魔術があります。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=ns.clj&quot;&gt;&lt;/script&gt;

;*CLJSBUILD-REMOVE*;はcljsbuildがビルド時に削除してくれるコメントです。
&lt;br /&gt;
core.logicがclj版とcljs版で違うnamespaceを使っているのでこうなっています。&lt;br /&gt;
&lt;br /&gt;
盤面で、空いているところはnilとします。&lt;br /&gt;
not-nil?という述語を作るために、!=を使いたいところですがcljs版に存在しないのでprojectを使います。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=not-nil.clj&quot;&gt;&lt;/script&gt;

projectはcore.logicで使われている変数にあたるものから値を取り出します。&lt;br /&gt;
&lt;br /&gt;
盤面が空いていたらコマを置く述語write。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=write.clj&quot;&gt;&lt;/script&gt;

コマが2連続で続いていたら自分であろうと相手であろうと決着します。&lt;br /&gt;
そのため、コマを優先して置く述語checkを定義します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=check.clj&quot;&gt;&lt;/script&gt;

これで補助の述語の定義は終りです。&lt;br /&gt;
あとは愚直に盤面を検査します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=play.clj&quot;&gt;&lt;/script&gt;

checkやwriteの順番を並べ変えると強くなったり弱くなったりします。&lt;br /&gt;
ここではなるべく中心にコマを置くように書いています。&lt;br /&gt;
&lt;br /&gt;
盤面から次の手を返す述語が定義できました。&lt;br /&gt;
もう1つ、ゲームが終了したか調べる述語も定義します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=end.clj&quot;&gt;&lt;/script&gt;

実際の使い方はこんな感じ。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=result.clj&quot;&gt;&lt;/script&gt;

敵味方の区別をつけていないので思った通りの手が返ってきていませんが、勝てないというのもつまらないのでこのままにします(手抜き)。&lt;br /&gt;
&lt;br /&gt;
これらの関数を使い、ゲームのロジックを書きます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4193337.js?file=game.clj&quot;&gt;&lt;/script&gt;

Canvasプロトコルを実装し、play関数を各パネルをクリックした時のhandlerとして登録することで動きます。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://basking-cat.blogspot.jp/2012/12/clojurejavafx-web-start.html&quot;&gt;JavaFXによる実装&lt;/a&gt;と&lt;a href=&quot;http://basking-cat.blogspot.jp/2012/12/clojurescriptgooggraphics.html&quot;&gt;goog.graphicsによる実装&lt;/a&gt;を書きました。
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
雑感&lt;/h3&gt;
&lt;br /&gt;
core.logicによる論理プログラミングは慣れていないせいか、とても頭をつかいました。&lt;br /&gt;
完成したコードは愚直だけれど分かり易いものになりました。&lt;br /&gt;
こういった書き方が出来ることが論理プログラミングの1つの利点でもあると思います。&lt;br /&gt;
&lt;br /&gt;
ゲームのロジックに関してはあまり綺麗に書けなかったのですが、各ライブラリと協調できるうまい書き方を知りたいものです。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/8121892142188642530/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/clojure.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/8121892142188642530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/8121892142188642530'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/clojure.html' title='Clojureで三目並べ'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-2589754118435349540</id><published>2012-12-01T07:09:00.000+09:00</published><updated>2012-12-01T07:10:30.555+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Isomorphism</title><content type='html'>&lt;a href=&quot;http://partake.in/events/7211abc9-ebb8-4670-b912-3089dc5e0edd&quot;&gt;Scalaz Advent Calendar!&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Isomorphism&lt;/h3&gt;
&lt;br /&gt;
あるcase classに対してMonoidを定義したいとき、大体のものはTupleのMonoidのインスタンスが使えると思います。&lt;br /&gt;
こんなときにIsomorphismMonoidが使えます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4071441.js?file=person.scala&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://gist.github.com/4071441.js?file=repl.scala&quot;&gt;&lt;/script&gt;

Monoid以外の型クラスを定義したい時もこんな感じで使える。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/4071441.js?file=iso.scala&quot;&gt;&lt;/script&gt;

このように、データ構造が同じもののインスタンスを流用する場合はIsomorphismが使えます。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;=&amp;gt;[A, B]はIso[Function1, A, B]のtype aliasで、to: A =&amp;gt; Bとfrom: B =&amp;gt; Aを定義します。&lt;br /&gt;
IsomorphismMonoidなどの型クラスは、toを使って実装されていることに注意しましょう。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/2589754118435349540/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/12/isomorphism.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/2589754118435349540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/2589754118435349540'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/12/isomorphism.html' title='Isomorphism'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-1134301298678818870</id><published>2012-10-31T19:41:00.000+09:00</published><updated>2012-10-31T19:41:05.298+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><title type='text'>ClojureでLisp評価器</title><content type='html'>SICP読書会、毎週月曜19時からmixiでやってます。&lt;br /&gt;
現在第４章の超循環評価器を作っています。&lt;br /&gt;
&lt;br /&gt;
4章の一番最初に出てくるevalの定義は以下の通り&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=eval.scm&quot;&gt;&lt;/script&gt;

とてもわかりやすいけど、データ主導にしたいよね、そうしよう、というのが問題4.3にあります。&lt;br /&gt;
&lt;br /&gt;
これをClojureっぽく書くことを考えてみる。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Protocol&lt;/h3&gt;
&lt;br /&gt;
ClojureといったらやっぱProtocolだよね！ということでプロトコルベースで考える。&lt;br /&gt;
とりあえず評価器プロトコル、Eval(uator)の定義&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=eval.clj&quot;&gt;&lt;/script&gt;

このプロトコルを実装したリテラルの評価器を書いてみる。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=literal.clj&quot;&gt;&lt;/script&gt;

部分関数っぽくしたいのだけど、例外を投げるか迷った。&lt;br /&gt;
今回はとりあえずこれで。&lt;br /&gt;
&lt;br /&gt;
このように、小さな評価器をいっぱい作って合成していくという考え方。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
special form&lt;/h3&gt;
&lt;br /&gt;
ifやdefineやbeginなんかのspecial formをチェックする関数tagged?の定義&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=tagged.clj&quot;&gt;&lt;/script&gt;

先頭要素を比較するだけ。&lt;br /&gt;
&lt;br /&gt;
これを使って、special formを以下のように表してみる&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=special.clj&quot;&gt;&lt;/script&gt;

Specialを使ったquote&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=quotation.clj&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;h3&gt;
if&lt;/h3&gt;
&lt;br /&gt;
ifは式を評価しなければいけない。&lt;br /&gt;
しかし、どの評価器を使えばいいのかわからない。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=divergence0.clj&quot;&gt;&lt;/script&gt;

評価器を引数にとるという選択肢もあるけど、不都合がある。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=lisp0.clj&quot;&gt;&lt;/script&gt;

この式を評価するとよくわからないエラーが投げられると思う。&lt;br /&gt;
ここでは評価機が部分適用されたeval関数をとることにする。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=divergence.clj&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;h3&gt;
compose&lt;/h3&gt;
&lt;br /&gt;
一番大事な評価器を合成する関数&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985858.js?file=compose.clj&quot;&gt;&lt;/script&gt;

やっていることは簡単、引数の先頭の評価器から順に、式を評価器で評価して失敗したら次の評価器で評価するという評価器を作っているだけ。&lt;br /&gt;
&lt;br /&gt;
これを使ってifとliteralだけが使えるlispを定義すると以下のようになる。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985858.js?file=lisp.clj&quot;&gt;&lt;/script&gt;

実行&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3985849.js?file=result.clj&quot;&gt;&lt;/script&gt;

ヤッター&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
まとめ&lt;/h4&gt;
&lt;br /&gt;
こんな感じで小さな評価器を書いていって大きな評価器を作っています。&lt;br /&gt;
なかなか楽しい。&lt;br /&gt;
&lt;br /&gt;
今回のプログラムはScalaBaseで&lt;a href=&quot;http://twitter.com/maeda_&quot; target=&quot;_blank&quot;&gt;@maeda_&lt;/a&gt;さんが発表されていた、&lt;a href=&quot;http://www.slideshare.net/maedaunderscore/scala-javascript-as-an-embedded-dsl-scalaexpression-problem&quot;&gt;Javascript as an Embedded DSL&lt;/a&gt;に触発されて書いてみました。&lt;br /&gt;
おもしろいので読んでみるとよいです。&lt;br /&gt;
&lt;br /&gt;
次はぱーさーこんびねーたについて書く、書きたい、書けたらいいな。 </content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/1134301298678818870/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojurelisp.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/1134301298678818870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/1134301298678818870'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojurelisp.html' title='ClojureでLisp評価器'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-5115398242691647079</id><published>2012-10-27T18:30:00.001+09:00</published><updated>2012-10-27T20:17:30.873+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="ClojureScript"/><title type='text'>Clojureのエラー処理</title><content type='html'>Clojureでエラー値を返すかもしれない関数ってどう書くのだろうとちょっと考えてみる。&lt;br /&gt;
&lt;br /&gt;
Scalaだと例外はあまり使わず、EitherやValidationを使う派。&lt;br /&gt;
やはり、コンパイラの恩恵を受けることが出来る書き方が良い。&lt;br /&gt;
&lt;br /&gt;
しかし、Clojureは動的型付けの言語。&lt;br /&gt;
コンパイラの恩恵は特にない。&lt;br /&gt;
&lt;br /&gt;
なので、 どのような値が返ると扱いやすいかを考える。&lt;br /&gt;
&lt;br /&gt;
Clojureは基本的に&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;nil返す&lt;/li&gt;
&lt;li&gt;例外投げる&lt;/li&gt;
&lt;/ul&gt;
の２通りだと思う。&lt;br /&gt;
&lt;br /&gt;
Clojure標準のライブラリはnilを渡してもそれなりに動作するし、if-let,when-let,fnilなどの関数も用意されている。&lt;br /&gt;
しかし、nilだとどのようなエラーだったのか判別がつかない。&lt;br /&gt;
このような時に例外を使って、エラーの種類によって投げる例外を変えれば良いのだと思う。&lt;br /&gt;
&lt;br /&gt;
Clojureの例外を投げるような関数は以下のように書ける。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3963746.js?file=ex.clj&quot;&gt;&lt;/script&gt;

この場合は、Java APIのIllegalArgumentExceptionとIndexOutOfBoundsExceptionを使った。&lt;br /&gt;
しかし、何時でもJava APIに自分が欲しいExceptionが定義されているわけではない。&lt;br /&gt;
このような時は、独自の例外を作るだろう。&lt;br /&gt;
&lt;br /&gt;
駄菓子菓子！&lt;br /&gt;
&lt;br /&gt;
Clojureでclassを定義するのはとても面倒。&lt;br /&gt;
&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/ns&quot;&gt;ns&lt;/a&gt;や&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/gen-class&quot;&gt;gen-class&lt;/a&gt;を見てもらえればわかると思う。&lt;br /&gt;
Throwableがinterfaceならば、deftypeやdefrecordが使えたのだけれど・・・&lt;br /&gt;
&lt;br /&gt;
例外を定義する部分だけJavaで書いたほうが楽かも。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3963746.js?file=ex.java&quot;&gt;&lt;/script&gt;

leiningenはJavaもサポートしているので、共存させるのは苦ではない。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
結論&lt;/h3&gt;
&lt;br /&gt;
基本的にnilを返す。&lt;br /&gt;
独自の例外を定義したかったらJavaを使うと楽&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/5115398242691647079/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojure_27.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5115398242691647079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5115398242691647079'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojure_27.html' title='Clojureのエラー処理'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-2534563198922077152</id><published>2012-10-13T16:06:00.002+09:00</published><updated>2012-10-14T07:00:48.327+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><title type='text'>Clojureでモナド内包表記とStateモナド</title><content type='html'>cljsbuildの&lt;a href=&quot;https://github.com/emezeske/lein-cljsbuild/blob/0.2.7/doc/CROSSOVERS.md&quot;&gt;crossovers&lt;/a&gt;という機能を知らない所為で今まで無駄に苦労してきましたが、これでマクロが使えないという制約から解き放たれました。&lt;br /&gt;
万歳！cljsbuild！&lt;br /&gt;
&lt;br /&gt;
マクロが使えるようになってまず一番最初にやることは何か？&lt;br /&gt;
もちろん、モナド内包表記の実現ですね！&lt;br /&gt;
&lt;br /&gt;
HaskellのdoよりはScalaのforの方が慣れているのでこちらを採用しました。&lt;br /&gt;
&lt;br /&gt;
動的型付けの言語でのモナドの実現はいくつか見てきましたが、明示的にコンテキストを指定するタイプはあまり好かないので、ClojureらしくProtocolで表現することにしました。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Monadic Protocol&lt;/h3&gt;
&lt;br /&gt;
通常モナドはunitとbindが実装され、モナド則&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;bind f (unit x) == f x&lt;/li&gt;
&lt;li&gt;bind unit m == m&lt;/li&gt;
&lt;li&gt;あともう一個なんかあった気がする&lt;/li&gt;
&lt;/ul&gt;
を満たしますが、動的型付けの言語でunitを実現するのは面倒なので、モナドっぽいインターフェースを定義します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=monadic.clj&quot;&gt;&lt;/script&gt;

このインターフェースが実装されていれば、モナド内包表記が使えるようになります。&lt;br /&gt;
とてもScala的。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
モナド内包表記&lt;/h3&gt;
&lt;br /&gt;
Lispは神の言語と皆ネタにしていますが、Lispのマクロは本当に強力です。&lt;br /&gt;
既存の言語にある構文の全てはLispのマクロで表現できるのではと思えるくらいです。&lt;br /&gt;
&lt;br /&gt;
Clojureの標準ライブラリではパターンマッチが出来ないので、準標準ライブラリであるcontribの&lt;a href=&quot;https://github.com/clojure/core.match&quot;&gt;core.match&lt;/a&gt;を使います。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=do_m.clj&quot;&gt;&lt;/script&gt;
しんぷるいずべすと、MonadPlusなんて知らないのでガードは実装しません。めんどい。&lt;br /&gt;
&lt;br /&gt;
このdo-mマクロがどのように展開してくれるかというと&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=expand.clj&quot;&gt;&lt;/script&gt;
が&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=expanded.clj&quot;&gt;&lt;/script&gt;

こんな感じになります。&lt;br /&gt;
&lt;br /&gt;
実際に動かしてみます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=example.clj&quot;&gt;&lt;/script&gt;

動いたー！&lt;br /&gt;
素敵です。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Stateモナド&lt;/h3&gt;
&lt;br /&gt;
私が現在製作中のアプリケーションでは、レコードを更新する関数が多数定義されています。&lt;br /&gt;
これは、状態をとって、新しい状態を返す関数ですが、少し問題があります。&lt;br /&gt;
&lt;br /&gt;
一つ例を示します。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=cursor.clj&quot;&gt;&lt;/script&gt;

このような関数が定義されていた時、右下へ移動する関数を定義するのに-&amp;gt;&amp;gt;マクロを使い、手続き的に書くことができます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=right_down.clj&quot;&gt;&lt;/script&gt;

しかし、このrightでの計算結果、つまりxを使う関数を定義する時、コードはこのようになります。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=square.clj&quot;&gt;&lt;/script&gt;

このパターンが関数内で頻出する場合、一時的なcursorの状態を保存する為の変数が増えてしまいます。&lt;br /&gt;
さらに、この場合はxを取得するコストは微々たるものですが、フィールドの取得に複雑なロジックを用いたり、計算値が状態の更新に間接的に使われるだけで、レコードからは取得できない場合があります。&lt;br /&gt;
&lt;br /&gt;
新しい状態だけを返すのではなく、計算値とのペアで返せばこのパターンを解決できます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=right.clj&quot;&gt;&lt;/script&gt;

しかし、-&amp;gt;&amp;gt;マクロのようにネストせずに書けるわけではありません。&lt;br /&gt;
&lt;br /&gt;
そこでStateモナドの出番です！（導入長い！&lt;br /&gt;
&lt;br /&gt;
Stateモナドは状態を取り、新しい状態と計算値のペアで返す関数に対してモナドを定義したものです。&lt;br /&gt;
&lt;br /&gt;
先ほど定義したMonadicをStateに実装してみます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883559.js?file=state.clj&quot;&gt;&lt;/script&gt;

right, down関数をStateで定義してみます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883607.js?file=state_function.clj&quot;&gt;&lt;/script&gt;

この時、square関数はdo-mを使って以下のように定義できます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3883607.js?file=state_square.clj&quot;&gt;&lt;/script&gt;

ヤッター！&lt;br /&gt;
&lt;br /&gt;
関数の合成が手続き的に書けますね。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
まとめ&lt;/h3&gt;
&lt;br /&gt;
マクロ強力。Stateモナド美しい。&lt;br /&gt;
&lt;br /&gt;
本当はFreeモナド使おうと思ったけどStateモナドの素晴らしさを伝えたかったので控えました。&lt;br /&gt;
&lt;br /&gt;
これから70個近い関数をStaeモナドに書き換える作業が待ってます。&lt;br /&gt;
Freeモナドの資料も作らなきゃですね。&lt;br /&gt;
私の代わりに大学のC言語の課題をやってくれるといいと思います。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/2534563198922077152/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojurestate.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/2534563198922077152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/2534563198922077152'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojurestate.html' title='Clojureでモナド内包表記とStateモナド'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-6861024467368812071</id><published>2012-10-03T20:23:00.002+09:00</published><updated>2012-10-03T20:24:10.148+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><title type='text'>Clojureへの不満とか</title><content type='html'>最近はClojureばかり書いているので、良い所ばかりでなく、気になるところも見えてきました。&lt;br /&gt;
&lt;br /&gt;
なにか意見をもらえるかもしれないので書き並べておきます。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
セルフホスティングして欲しい&lt;/h3&gt;
&lt;br /&gt;
Clojureのソースコードを読むときに、高確率でJavaのコードを読まなければいけないので悲しくなります。&lt;br /&gt;
やはり、gen-classとかでは物足りないのかなあ？&lt;br /&gt;
それとも、セルフホスティングにはあまりヤル気がないのか・・・・&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
clojure.langのJavaDoc欲しい&lt;/h3&gt;
&lt;br /&gt;
ソースコード追うのが面倒なので。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Protocolをもっと使って欲しい&lt;/h3&gt;
&lt;br /&gt;
自分で新しいデータ型を作った時に、既存の関数を使うためにclojure.langの得体の知れないinterfaceを実装するわけですが、Protocolとして存在すればClojureの中で完結するのでうれしいのだけど、これはデータ型がJavaに依存しすぎてて簡単にはいかないんだろうなあと。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
関数が返す値は適用する値と同じデータ型で返して欲しい&lt;/h3&gt;
&lt;br /&gt;
特にStringとか。&lt;br /&gt;
charのシーケンスで返ってくるのが悲しい。&lt;br /&gt;
これはなぜだろう、効率のためかな？&lt;br /&gt;
どこかで読んだ気がしなくもない。&lt;br /&gt;
&lt;br /&gt;
いっそのことClojure独自に文字列作るというのは・・・・まあ、それはそれで面倒臭そう。&lt;br /&gt;
&lt;br /&gt;
Scalazは独自に&lt;a href=&quot;http://halcat0x15a.github.com/scalaz/core/target/scala-2.9.2/api/#scalaz.Cord&quot;&gt;Cord&lt;/a&gt;というデータ型を定義しています。&lt;br /&gt;
さすが、尖ってる。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
insertしたい&lt;/h3&gt;
&lt;br /&gt;
&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html&quot;&gt;ArrayList&lt;/a&gt;や&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html&quot;&gt;LinkedList&lt;/a&gt;を使えばいいのですが、functionalでpurelyなdata structureが欲しいわけです。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Arrowが欲しい&lt;/h3&gt;
&lt;br /&gt;
Haskellのfirst,secondに当たるものが欲しい。&lt;br /&gt;
分配束縛したくない。&lt;br /&gt;
もっとポイントフリーなプログラミングがしたいのです。&lt;br /&gt;
&lt;br /&gt;
しかし、&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/comp&quot;&gt;comp&lt;/a&gt;と&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/partial&quot;&gt;partial&lt;/a&gt;と&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/juxt&quot;&gt;juxt&lt;/a&gt;でやりすぎたコードを書くのには注意です。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;a href=&quot;http://if-let/&quot;&gt;if-let&lt;/a&gt;, &lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/when-let&quot;&gt;when-let&lt;/a&gt;が１つの変数しか束縛できない&lt;/h3&gt;
&lt;br /&gt;
なぜ複数束縛できないのか・・・・・&lt;br /&gt;
&lt;br /&gt;
要素を１つだけ持つlistと&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/map&quot;&gt;map&lt;/a&gt;と&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/mapcat&quot;&gt;mapcat&lt;/a&gt;または&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/for&quot;&gt;for&lt;/a&gt;を使って、Maybeモナドっぽいことは出来ます。&lt;br /&gt;
あとは(fn [a] (if (nil? a) (list) (list a)))のようなものがあるといいのだけど。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
do記法、for内包、コンピュテーション式にあたるものが欲しい&lt;/h3&gt;
&lt;br /&gt;
&lt;a href=&quot;http://clojuredocs.org/clojure_core/clojure.core/for&quot;&gt;for&lt;/a&gt;内包はあることにはあります。&lt;br /&gt;
しかし、これはSequableでSequentialなデータ型（JavaのIterableとIteratorのようなもの？）の為のもので、モナドの為のマクロではないです。&lt;br /&gt;
&lt;br /&gt;
Maybeモナドやdo記法は&lt;a href=&quot;https://github.com/clojure/algo.monads&quot;&gt;algo.monads&lt;/a&gt;で提供されていますが、あまり設計に納得がいかない。&lt;br /&gt;
私はあるデータ型に対してモナドを定義したいので、Protocolをベースに設計したものが欲しかった。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
限定継続が欲しい&lt;/h3&gt;
&lt;br /&gt;
do記法がないなら限定継続を使えばいいじゃないと昔の貴族は言ったものです。&lt;br /&gt;
限定継続があれば括弧を減らせるような構文がいろいろと簡単に定義できそうだなあと思い挙げてみた。&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/swannodette/delimc&quot;&gt;delimic&lt;/a&gt;といものがあるらしい。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
まとめ&lt;/h3&gt;
&lt;br /&gt;
私はいままではScalaばかり書いていましたが、いまはClojureばかり書いているのでこのような記事を書いています。&lt;br /&gt;
実際には2年前くらいから少しずつ書いていましたが、これほどClojureを書いてる期間はありませんでした。 &lt;br /&gt;
&lt;br /&gt;
Scalaに触れ、さらにScalazに触れたことで完全に関数型プログラミング信者になってしまいましたが、実際に有用な技法を多く知ることが出来ました。&lt;br /&gt;
それをClojureで実現するために、このような贅沢な不満が出てきました。 &lt;br /&gt;
&lt;br /&gt;
Clojureはまだまだ若い言語だと思うので、あれもこれもと求め過ぎていると思います。&lt;br /&gt;
なので、今後私が期待しているものに発展してくれるようClojureに貢献していきたいです。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/6861024467368812071/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojure.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/6861024467368812071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/6861024467368812071'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/10/clojure.html' title='Clojureへの不満とか'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-6024206699361033241</id><published>2012-09-13T16:23:00.000+09:00</published><updated>2012-09-13T16:23:02.768+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="ClojureScript"/><title type='text'>ClojureScriptのテスト</title><content type='html'>皆さんテスト書いてますか？&lt;br /&gt;
私はあまり書いてません。&lt;br /&gt;
テストは大事です、書きましょう。&lt;br /&gt;
&lt;br /&gt;
私は現在ClojureScriptを使っているのですが、JavaScriptでのテスト方法とかよくわからないし、Clojureでテスト書きたいので、ClojureからClojureScriptを読み込もうという考えに至りました。&lt;br /&gt;
&lt;br /&gt;
が、しかし。&lt;br /&gt;
requireなどを使って、ClojureScriptのコードを読み込むことはできませんでした。&lt;br /&gt;
なぜなら拡張子がcljsだから。&lt;br /&gt;
load-fileなども使ってみましたが、無理でした。&lt;br /&gt;
ClojureScriptのコードの中でrequireを使っているからです。&lt;br /&gt;
&lt;br /&gt;
どうにかして拡張子がclj,classのファイル以外を読み込むことはできないのかと調べてみたところ・・・・&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L403&quot;&gt;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L403&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
ベタ書き・・・！&lt;br /&gt;
差し替えることなど到底無理っぽい。&lt;br /&gt;
&lt;br /&gt;
ならば作るしかありません、cljファイルを。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3712555.js?file=gistfile1.clj&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
copyしてuseしてdeleteする、悲しみあふれるコード。&lt;br /&gt;
cleanupのところはtry-finallyした方が良いかも。&lt;br /&gt;
&lt;br /&gt;
clojure.testはfailした時にマクロを利用して述語に渡した値を展開してくれたりでなかなか便利なので割と好きです。&lt;br /&gt;
しかし、ここまでして使うのもどうかなと。&lt;br /&gt;
&lt;br /&gt;
素直にJavaScriptのテストフレームワークを使うとか、assertで済ませる（ClojureScript本体のテスト方法）などでいいかもしれません。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/6024206699361033241/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/09/clojurescript.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/6024206699361033241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/6024206699361033241'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/09/clojurescript.html' title='ClojureScriptのテスト'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-5683550861419945147</id><published>2012-09-10T15:08:00.001+09:00</published><updated>2012-09-11T00:16:10.491+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Scalaでdo記法</title><content type='html'>&lt;a href=&quot;http://partake.in/events/9a5f18bf-ca0c-48cd-a050-8a564c1ab0d9&quot;&gt;函数プログラミングの集い&lt;/a&gt;で限定継続の話が面白かったので書いておきます。&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;ja&quot;&gt;
_ &amp;lt;- 省略できたらいいのになあ &lt;a href=&quot;https://twitter.com/search/%23start_scalaz&quot;&gt;#start_scalaz&lt;/a&gt;&lt;br /&gt;
— Toshiyuki Takahashiさん (@tototoshi) &lt;a data-datetime=&quot;2012-09-09T06:43:55+00:00&quot; href=&quot;https://twitter.com/tototoshi/status/244687561979748353&quot;&gt;9月 9, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script charset=&quot;utf-8&quot; src=&quot;//platform.twitter.com/widgets.js&quot;&gt;&lt;/script&gt;

ScalaでもHaskellのdo記法っぽく書ける。&lt;br /&gt;
&lt;br /&gt;
調度良くScalaでHaskellしてる&lt;a href=&quot;http://d.hatena.ne.jp/xuwei/20120909/1347207862&quot;&gt;記事&lt;/a&gt;があったので、これを参考にさせていただきます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3689154.js?file=gistfile1.scala&quot;&gt;&lt;/script&gt;

＼めんどい／&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;※追記&lt;br /&gt;
&lt;br /&gt;
実践Scalaプログラミング読みなおしてみたらこっちの方が良さそう。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3691189.js?file=gistfile1.scala&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
しかし、完全に推論させることは出来なさそう。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;for式使いましょう。&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/5683550861419945147/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/09/scalado.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5683550861419945147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5683550861419945147'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/09/scalado.html' title='Scalaでdo記法'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-264153646687588463</id><published>2012-09-05T08:13:00.000+09:00</published><updated>2012-09-05T08:13:21.135+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="ClojureScript"/><title type='text'>Clojureのinsert</title><content type='html'>Clojureでlistやvectorのｎ番目に値をinsertしたい時はありませんか?&lt;br /&gt;
Clojureには標準でlistやvectorに対するinsertが定義されていません。&lt;br /&gt;
でもzipperにはinsertがあるみたい。&lt;br /&gt;
そこでvectorとzipper、どちらのinsertが速いか測ってみました。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
コード&lt;/h3&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3627818.js?file=insert.clj&quot;&gt;&lt;/script&gt;

&lt;h3&gt;
結果&lt;/h3&gt;
&lt;br /&gt;
ClojureScript&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3627818.js?file=cljs.cljs&quot;&gt;&lt;/script&gt;

Clojure &lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3627818.js?file=clj.clj&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://gist.github.com/3627818.js?file=big.clj&quot;&gt;&lt;/script&gt;

思っていたよりは差がつかなかった。&lt;br /&gt;
&lt;br /&gt;
vectorやlistはいつもこんな感じでinsertしてるのですが、もっと綺麗で効率のよい方法があったら教えて下さい。&lt;br /&gt;
&lt;br /&gt;
効率のよいinsertが出来るシーケンスを標準で用意してくれてもいいのではと思わなくもないです。 </content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/264153646687588463/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/09/clojureinsert.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/264153646687588463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/264153646687588463'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/09/clojureinsert.html' title='Clojureのinsert'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-6782606014250036167</id><published>2012-09-01T06:21:00.000+09:00</published><updated>2012-09-01T06:21:10.636+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><category scheme="http://www.blogger.com/atom/ns#" term="Scalaz"/><title type='text'>Machines</title><content type='html'>先日&lt;a href=&quot;http://www.scala-users.org/shibuya/index.php?title=%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8&quot;&gt;rpscala&lt;/a&gt;に行った時、&lt;a href=&quot;https://twitter.com/xuwei_k&quot;&gt;@xuwei_k&lt;/a&gt;さんに&lt;a href=&quot;https://github.com/runarorama/scala-machines&quot;&gt;scala-machines&lt;/a&gt;というものを教えてもらったので調べてみました。&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/goog_1711609441&quot;&gt;&lt;br /&gt;&lt;/a&gt;
&lt;a href=&quot;https://github.com/runarorama/scala-machines/blob/master/src/main/scala/com/clarifi/machines/Example.scala&quot;&gt;Example.scala&lt;/a&gt;を参考に、コードを読んでいきます。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=machines.scala&quot;&gt;&lt;/script&gt;

少々書き換えました。&lt;br /&gt;
&lt;br /&gt;
ぱっと見ても全くわからないですね。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
IO&lt;/h4&gt;
&lt;br /&gt;
副作用（アクション）を表します。&lt;br /&gt;
IO.applyは値をcall by nameでとります。 &lt;br /&gt;
unsafePerformIOを呼ぶことで、アクションを実行します。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
bufferFile&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=bufferFile.scala&quot;&gt;&lt;/script&gt;

ファイルをとってBufferedReaderを返す関数です。&lt;br /&gt;
IOでラップしています。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
rReadLn&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=rReadLn.scala&quot;&gt;&lt;/script&gt;

BufferedReaderから一行読み取ります。&lt;br /&gt;
readLineは文字列かnullを返すのでOption.applyを使用しています。&lt;br /&gt;
これもIOでラップしています。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
closeReader&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=closeReader.scala&quot;&gt;&lt;/script&gt;

Readerを閉じます。&lt;br /&gt;
当然副作用なのでIOでラップされます。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Process&lt;/h4&gt;
&lt;br /&gt;
Process[I, O]はI =&amp;gt; Oをラップしたものと考えていい・・・・はず。&lt;br /&gt;
Process[I, O]はMachine[I =&amp;gt; Any, O]のシノニムで、Machine[K, O]はPlan[K, O, Nothing]のシノニムなので、実体はPlanなわけですが、まだ私は理解できていません。 &lt;br /&gt;
IterateeのIteratee,Enumeratee,Enumeratorの内のIterateeにあたるようなものだと思われます。&lt;br /&gt;
なのでストリームの要素はこいつを使って処理していきます。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
countLn&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=countLn.scala&quot;&gt;&lt;/script&gt;

文字列をとって1を返すProcessです。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
getFileLines&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=getFileLines.scala&quot;&gt;&lt;/script&gt;

型パラメータAとProcess[String, A]とFileをとり、Procedure[IO, A]を返します。&lt;br /&gt;
モナド変換子と同じく、Procedureから値Aを取り出す時にIOにラップされるようになります。 &lt;br /&gt;
ProcedureはEnumeratorのようなもので、ストリームとそれを処理するMachineを持ちます。&lt;br /&gt;
ProcedureはMachineの第一型パラメータとMachine、抽象メソッドのwithDriverを定義します。&lt;br /&gt;
Process[I, O]は先述の通りMachine[I =&amp;gt; Any, O]と定義されているので、抽象タイプメンバにはString =&amp;gt; Any、Machineは引数としてとったProcessで定義します。&lt;br /&gt;
Driverでは入力を定義するのですが、当然、入力にはリソースが必要になります。&lt;br /&gt;
そこで、このwithDriverではリソースの作成、開放、Driver（入力）の作成、Driverの適用を定義します。&lt;br /&gt;
リソースの作成はbufferedReaderを使います。&lt;br /&gt;
IO#bracket(f)(g)は処理gの後に必ず処理fが処理されます。 &lt;br /&gt;
事後処理としてcloseReaderを渡し、Driverの作成と適用をします。&lt;br /&gt;
DriverにはrReadLnを使い、入力を適用するapplyを定義します。&lt;br /&gt;
最後にwithDriverがとる関数kにDriverを適用します。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
exec&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=exec.scala&quot;&gt;&lt;/script&gt;

ファイルを関数に適用し、実行、出力する関数です。&lt;br /&gt;
executeはProcedureの結果の型Aがモノイドである必要があります。&lt;br /&gt;
ストリームを処理した結果をaccumulatorに加える関数で合成していきます。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
runc&lt;/h4&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=runc.scala&quot;&gt;&lt;/script&gt;

main関数で呼ばれる関数で、裏でunsafePerformIOを呼びます。&lt;br /&gt;
&lt;br /&gt;
CSVファイルの読み込みと要素のカウントを書いてみた。&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3559093.js?file=CSV.scala&quot;&gt;&lt;/script&gt;

&lt;h3&gt;
まとめ&lt;/h3&gt;
&lt;br /&gt;
IterateeよりはIOに特化していると思われる。&lt;br /&gt;
リソースの処理をProcedureでやっているところとか。&lt;br /&gt;
ProcessやProcedureを自分で書くのは、IterateeやEnumeratorを自分で書くよりは楽・・・・な気がしなくもない。&lt;br /&gt;
&lt;br /&gt;
今回は本当にExampleをさわっただけで、詳細はわかっていない。&lt;br /&gt;
作者のドキュメントに期待です。</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/6782606014250036167/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/09/machines.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/6782606014250036167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/6782606014250036167'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/09/machines.html' title='Machines'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3707366315089692807.post-5415508756850283967</id><published>2012-08-26T04:17:00.000+09:00</published><updated>2012-08-26T04:17:12.612+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clojure"/><category scheme="http://www.blogger.com/atom/ns#" term="ClojureScript"/><title type='text'>ClojureScript</title><content type='html'>最近はClojureScriptばかり書いてます。&lt;br /&gt;
Clojureを書いてるとJavaを意識しなければいけないことがありますが、ClojureScriptも同じでJavaScriptを意識しなければなりません。&lt;br /&gt;
とはいってもJavaScriptを書くよりも遥かに快適なので是非広まって欲しいものです。&lt;br /&gt;
&lt;br /&gt;今日までにClojureScriptを書いてきて、わかったことを少しまとめようと思います。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
clojure.browser&lt;/h3&gt;
&lt;br /&gt;
Google Closure Libraryのラッパーで、domやevent、netなどのライブラリがあります。&lt;br /&gt;
domとeventを触りましたが、ものすごく中途半端です。&lt;br /&gt;
結局goog.domやgoog.eventの関数が必要になるので、 まだまだ発展途上と言えるでしょう。&lt;br /&gt;
&lt;br /&gt;
Closure Libraryの関数はJavaScriptのArrayやObjectを扱うものが多く、ClojureScriptのデータ型を渡すときに少々不便だったりします。&lt;br /&gt;
clojure.browserはそういった不満を解消するものとなってほしいです。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ちょっと便利な関数&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;clojure.browser.dom/ensure-element&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;keywordを渡すとgetElementとして、 stringを渡すとhtmlToDocumentFragmentとして動きます&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;clojure.browser.dom/log&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Console#logです&lt;/li&gt;
&lt;li&gt;*print-fn*にset!するのが一般的？&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;h3&gt;
ClojureとJavaScript&lt;/h3&gt;
&lt;br /&gt;JavaScriptの世界で生きていくためにはClojureの標準ライブラリの関数だけでは生きていけません。&lt;br /&gt;
なので、ClojureScriptにはClojureとJavaScriptの間を取り持つ関数が存在します。&lt;br /&gt;
しかし、ドキュメントが少なすぎて存在があまり知られていないように感じます。かなしい。&lt;br /&gt;
&lt;br /&gt;
js-objとarrayは特に重要です。&lt;br /&gt;
それぞれObjectとArrayを生成する関数です。&lt;br /&gt;
主にClosure Libraryの関数を呼び出す為に使います。&lt;br /&gt;
js-keysやjs-deleteなんかも覚えておきましょう。&lt;br /&gt;
&lt;br /&gt;
JavaScriptを直接実行するjs*なんかもありますが、最終手段とするべきでしょう。&lt;br /&gt;
&lt;br /&gt;
array-seqも便利です。&lt;br /&gt;
JavaScriptのArray的データ型（NodeList, FileListなど）をClojureScriptのデータ型に変換するものです。&lt;br /&gt;
(extend-type Hoge ISeqable (-seq [hoge] (array-seq hoge)))&lt;br /&gt;
としておくとClojureScriptのコレクション関連の関数が使えて便利になります。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
外部ライブラリ&lt;/h3&gt;
&lt;br /&gt;
ちゃんとClojureScriptのライブラリだって存在します。&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;core.match&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;パターンマッチを提供してくれるライブラリ、便利。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;core.logic&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;JavaScriptで論理プログラミングが出来るよ！やったね！&lt;/li&gt;
&lt;li&gt;しかしバグあるしあまり期待しないほうがいい。&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;h3&gt;
読まなければいけないもの&lt;/h3&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure&quot;&gt;https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://himera.herokuapp.com/synonym.html&quot;&gt;http://himera.herokuapp.com/synonym.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
ClojureScriptやりましょうず！</content><link rel='replies' type='application/atom+xml' href='http://basking-cat.blogspot.com/feeds/5415508756850283967/comments/default' title='コメントの投稿'/><link rel='replies' type='text/html' href='http://basking-cat.blogspot.com/2012/08/clojurescript.html#comment-form' title='0 件のコメント'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5415508756850283967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3707366315089692807/posts/default/5415508756850283967'/><link rel='alternate' type='text/html' href='http://basking-cat.blogspot.com/2012/08/clojurescript.html' title='ClojureScript'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12251480673276087074</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>