Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jsofra
Created October 17, 2011 23:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsofra/1294142 to your computer and use it in GitHub Desktop.
Save jsofra/1294142 to your computer and use it in GitHub Desktop.
Config using optional named parameters
(def ^:dynamic *config* nil)
(defn save [data & {:keys [config] :or {config *config*}}]
(println (format "Saved %s with %s" data config)))
;; => (save {:a 5 :b 6} :config {:some :config})
;; Saved {:a 5, :b 6} with {:some :config}
;; nil
;; => (binding [*config* {:some :config}] (save {:a 5 :b 6}))
;; Saved {:a 5, :b 6} with {:some :config}
;; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment