«前の日記(2017-05-31) 最新 次の日記(2017-06-03)» 編集

ToDo:

  • 99 深呼吸して、おちけつ (~12/31 あと287日)
  • 98 毎日アウトプットを重きにおいた目標をたてる (~12/31 あと287日)
  • 97 買物は行動を変えるもの・ことに限る (~12/31 あと287日)
  • 96 合理的な行動はときに我慢を強いる(~12/31 あと287日)

ɥozɐʞıɥ


2017-06-02 Clojureでcore.async [長年日記]

_ [Clojure] core.async

少しだけ時間が取れ始めたのでお勉強です。Clojureは面白い。

(defproject async "0.1.0-SNAPSHOT"

:description "FIXME: write description"

:url "http://example.com/FIXME"

:main async.core

:aot [async.core]

:license {:name "Eclipse Public License"

:url "http://www.eclipse.org/legal/epl-v10.html"}

:dependencies [[org.clojure/clojure "1.8.0"]

[org.clojure/core.async "0.3.443"]])

でcore.asyncを依存関係に入れちゃいます。

goマクロのbodyのみ>!や<!のシングルビックリマーク!使えるようです。

なのでgoマクロから呼ばれた関数でもNGでした。

ブロックするのでmainはダブル吃驚マーク!!です。

(ns async.core

(:require [clojure.core.async

:as a

:refer [>! <! >!! <!! go chan buffer close! thread

alts! alts!! timeout]])

(:gen-class))

(defn go01[ch]

(go

(println "Start 01")

(loop [i 0]

(Thread/sleep 100)

(println "Going 01!")

(if (< i 10)

(recur (inc i))

(>! ch "01")))))

(defn go02[ch]

(go

(println "Start 02")

(loop [i 0]

(Thread/sleep 50)

(println "Going 02")

(if (< i 10)

(recur (inc i))

(>! ch "02")))))

(defn -main[& args]

(let [ch (chan 2)]

(go01 ch)

(go02 ch)

(println (<!! ch))

(println (<!! ch))))

_ [買物][] ブラウン神父の童心

古典的な推理小説が面白いのです。



2002|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|
«前の日記(2017-05-31) 最新 次の日記(2017-06-03)» 編集