Skip to content

Instantly share code, notes, and snippets.

@ujihisa
Created September 7, 2011 05:19
Show Gist options
  • Save ujihisa/1199821 to your computer and use it in GitHub Desktop.
Save ujihisa/1199821 to your computer and use it in GitHub Desktop.
(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]))))
(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]))
(def *x* 0)
(defn f [i]
(if (= i 5)
(alter-var-root #'*x* (fn [_] 1))
nil)
(println [i *x*]))
(pmap f (range 10))
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