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 ^:dynamic *gentemp-counters*) | |
(defn new-gentemp-counters [] {}) | |
(defn next-name [name] | |
(let [c (get *gentemp-counters* name 0)] | |
(set! *gentemp-counters* (assoc *gentemp-counters* name (inc c))) | |
(str name "-" c))) | |
(defmacro with-reset-ids [& body] | |
`(binding [*gentemp-counters* (new-gentemp-counters)] |
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 Data::UUID; | |
#use RDF::Trine::Serializer::Turtle; | |
#use RDF::Trine::Serializer::Notation3; | |
use RDF::Trine::Serializer::NTriples; | |
use RDF::Trine::Namespace qw(rdf); | |
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
;; the simple example: | |
(with-local-vars [foo 0] | |
(var-set foo (+ 1 (var-get foo))) | |
(var-get foo)) | |
;; the reason why - a call back | |
;; (this code still needs some cleaning) | |
;; the TupleQueryResultHandler is called once per result of the query | |
(defn sesame-visit-count-sparql [kb query-string] | |
(with-local-vars [count 0] |
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
(defmacro kb-test [name triples & body] | |
`(defn ~name [kb-creator] | |
(binding [*kb* (new-test-kb kb-creator ~triples)] | |
~@body))) | |
create this: | |
user> (macroexpand-1 '(kb-test test-kb-up test-triples | |
(is kb))) |
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
(defmacro binding-non-default-fn [fn-name default-specials args & body] | |
(let [special-vars (vec (doall (map gensym default-specials)))] | |
`(defn ~fn-name | |
(~args ~@body) | |
(~(vec (concat special-vars args)) | |
(binding ~(vec (interleave default-specials special-vars)) | |
~@body))))) | |
call: |