Created
August 17, 2011 05:23
-
-
Save drlivingston/1150860 to your computer and use it in GitHub Desktop.
using a var to count a callback
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] | |
(.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