Created
September 7, 2011 05:19
-
-
Save ujihisa/1199821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def x 1) | |
(def y 10) | |
(defn useit [] | |
(print "------------") | |
(println x)) | |
(binding [x (+ x 1)] (useit)) | |
(binding [x (+ x 1)] ((fn [] (println x)))) | |
(let [x (+ x 1)] (useit)) | |
(let [x (+ x 1) y 1] ((fn [] (println [x y])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrecord ModelState [state input-event output-event]) | |
(defn run-state [init q c xs] | |
;(letfn f [x] | |
;(pmap f xs) | |
(for [a (reductions c init xs)] | |
(do | |
(q (:output-event a)) | |
(println a)))) | |
(def *query-state* '()) | |
(defn query-model [output-event] | |
(println [output-event (Thread/currentThread)]) | |
(if (= output-event "it was the world") | |
(alter-var-root | |
#'*query-state* | |
(fn [_] | |
(Thread/sleep 2000) | |
(println 'ichanged) | |
'hi)) | |
nil) | |
(println *query-state*) | |
output-event) | |
(defn command-model [previous-state event] | |
(let [output (if (= event 'world) "it was the world" nil)] | |
(assoc previous-state | |
:state (cons event (:state previous-state)) | |
:input-event event | |
:output-event output))) | |
(println (Thread/currentThread)) | |
(doall | |
(run-state (ModelState. '() nil "") query-model command-model ['hello 'world 'aaa 'bbb 'ccc 'ddd])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def *x* 0) | |
(defn f [i] | |
(if (= i 5) | |
(alter-var-root #'*x* (fn [_] 1)) | |
nil) | |
(println [i *x*])) | |
(pmap f (range 10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 0 | |
f = -> i { | |
if i == 5 | |
x = 1 | |
end | |
p [i, x] | |
} | |
(0...10).map {|i| | |
Thread.new do | |
f.(i) | |
end | |
}.map(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment