Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created January 11, 2012 06:25
Show Gist options
  • Save wjlafrance/1593355 to your computer and use it in GitHub Desktop.
Save wjlafrance/1593355 to your computer and use it in GitHub Desktop.
(defn pfilter [pred coll]
"perform filter in parallel"
(map second
(filter first
(pmap (fn [item] [(pred item) item]) coll)
)
)
)
(defn is-divisible [x y]
"determine if x / y is an integer"
(=
(/ (float x) (float y))
(float (int (/ (float x) (float y))))
)
)
(defn is-prime [x]
"determine if a number is prime"
(with-local-vars [value true y (- x 1)]
(while (> (var-get y) 1)
(if (is-divisible x (var-get y))
(var-set value false)
)
(var-set y (- (var-get y) 1))
)
(not (not (var-get value)))
)
)
(defn main []
(println (pfilter is-prime (range 1 100000 1)))
(shutdown-agents)
)
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment