Skip to content

Instantly share code, notes, and snippets.

View ericnormand's full-sized avatar

Eric Normand ericnormand

View GitHub Profile
;; this one looks much cleaner, but it holds onto the heads of the lists
(defn filter-collecting [predicate collector & lists]
(let [tuples (apply map vector lists)
filtered (filter #(apply predicate %) tuples)]
(map #(apply collector %) filtered)))
;; less garbage, but uglier
(defn filter-collecting [predicate collector & lists]
(def end (p/not-followed-by p/anything))
(def lang1
(p/alt
(p/invisi-conc (term (partial = :a)) end)
(p/invisi-conc (term (partial = :a)) (term (partial = :a)) end)))
(def lang2
(p/invisi-conc (p/alt (term (partial = :a))
(p/invisi-conc (term (partial = :a)) (term (partial = :a))))
(use 'clj-reasoner)
;; a graph of explicit friendship relations
(def friends-graph
(build-graph [{:s "Andrew" :r "hasFriend" :o "John"}
{:s "Chris" :r "hasFriend" :o "Andrew"}
{:s "Jane" :r "hasFriend" :o "Linda"}
{:s "Jane" :r "hasFriend" :o "Chris"}]))
(use 'clj-reasoner)
;; friendship is symmetrical
(def friend-symm
[[{:s '?p :r "hasFriend" :o '?f}]
[{:s '?f :r "hasFriend" :o '?p}]])
(use 'clj-reasoner)
;; friendship is transitive
(def friend-trans
[[{:s '?p :r "hasFriend" :o '?q}
{:s '?q :r "hasFriend" :o '?r}]
[{:s '?p :r "hasFriend" :o '?r}]])
(use 'clj-reasoner)
(infer-all-closure friends-graph [friend-symm friend-trans])
(use 'clj-reasoner)
(apply infer friends-graph friend-symm)
(use 'clj-reasoner)
(apply infer (apply infer friends-graph friend-symm) friend-trans)
(def method (GetMethod. "http://www.google.com"))
;; . . . do stuff . . .
(def stream (.getResponseBodyAsStream method)
(auto-wrapper stream [InputStream] []
(close []
(.close stream)
(.releaseConnection method)))
(let [wrapped2399 stream]
(proxy
[InputStream]
[]
(markSupported ([] (.markSupported wrapped2399)))
(available ([] (.available wrapped2399)))
(toString ([] (.toString wrapped2399)))
(mark ([a0] (.mark wrapped2399 a0)))
(reset ([] (.reset wrapped2399)))
(read