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
;; 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] |
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 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)))) |
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
(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"}])) |
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
(use 'clj-reasoner) | |
;; friendship is symmetrical | |
(def friend-symm | |
[[{:s '?p :r "hasFriend" :o '?f}] | |
[{:s '?f :r "hasFriend" :o '?p}]]) |
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
(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}]]) |
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
(use 'clj-reasoner) | |
(infer-all-closure friends-graph [friend-symm friend-trans]) |
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
(use 'clj-reasoner) | |
(apply infer friends-graph friend-symm) |
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
(use 'clj-reasoner) | |
(apply infer (apply infer friends-graph friend-symm) friend-trans) |
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 method (GetMethod. "http://www.google.com")) | |
;; . . . do stuff . . . | |
(def stream (.getResponseBodyAsStream method) | |
(auto-wrapper stream [InputStream] [] | |
(close [] | |
(.close stream) | |
(.releaseConnection method))) |
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
(let [wrapped2399 stream] | |
(proxy | |
[InputStream] | |
[] | |
(markSupported ([] (.markSupported wrapped2399))) | |
(available ([] (.available wrapped2399))) | |
(toString ([] (.toString wrapped2399))) | |
(mark ([a0] (.mark wrapped2399 a0))) | |
(reset ([] (.reset wrapped2399))) | |
(read |
OlderNewer