Skip to content

Instantly share code, notes, and snippets.

@martinklepsch
Last active August 29, 2015 14:26
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 martinklepsch/2e4a20e98ead0ed6953d to your computer and use it in GitHub Desktop.
Save martinklepsch/2e4a20e98ead0ed6953d to your computer and use it in GitHub Desktop.
(core/defmacro define
[sym default]
(assert-args define
(core/or (core/string? default)
(core/number? default)
(core/true? default)
(core/false? default)) "a string, number or boolean as default value")
(core/let [defname (cljs.compiler/munge (core/str *ns* "/" sym))
type (core/cond
(core/string? default) "string"
(core/number? default) "number"
(core/or (core/true? default) (core/false? default)) "boolean")]
`(do
(declare ~(symbol sym))
(~'js* ~(core/str "/** @define {" type "} */"))
(goog/define ~defname ~default))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment