-
-
Save cespare/6f966059a1b49f3f437c to your computer and use it in GitHub Desktop.
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
; I've got a function like this: | |
(defn parse-from-bytes [type bytes] ...) | |
; that knows how to parse a binary protocol into a certain type. | |
; Custom parsers are generated for each type by a macro, say gen-parser: | |
(defmacro gen-parser [type] ...) | |
; So when you call parse-from-bytes, it checks to see whether a parser | |
; was previously generated for that type, and calls it. | |
; | |
; My thought for how to accomplish this was to define a private atom | |
(def ^{:private true} parser-cache (atom {})) | |
; and then have gen-parser emit code like | |
(swap! #'ns/parser-cache assoc type parse-fn) | |
; But this doesn't work because swap sees a var and not an atom. | |
; So my questions: | |
; 1. Is there a better overall approach I should be using? | |
; 2. (Assuming I want to keep parser-cache private) how can I refer | |
; to a private atom? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment