Skip to content

Instantly share code, notes, and snippets.

@drlivingston
Created August 17, 2011 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drlivingston/1150860 to your computer and use it in GitHub Desktop.
Save drlivingston/1150860 to your computer and use it in GitHub Desktop.
using a var to count a callback
;; 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]
(.evaluate ^TupleQuery
(.prepareTupleQuery ^RepositoryConnection (connection! kb)
QueryLanguage/SPARQL
query-string)
(proxy [TupleQueryResultHandlerBase] []
(handleSolution [bindings]
(var-set count
(+ 1 (var-get count))))))
(var-get count)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment