Reputation: 4093
(defmacro get-color [color-name]
`@(thi.ng.color.core/as-int32 (var-get (resolve (symbol "thi.ng.color.core"
(str '~color-name))))))
I like to avoid using the (var-get (resolve (symbol ... (str '~parem))))
. Something like thi.ng.color.core/(~color-name)
.
(I am using this macro in a very small personal project, and I don't care if it's really bad practice to create a macro for this use case. Though I like knowing why it would be problematic in bigger projects.)
Upvotes: 0
Views: 78
Reputation: 34800
(require 'thi.ng.color.core)
(defmacro get-color
[color-name]
(let [sym (symbol "thi.ng.color.core"
(str color-name))]
`@(thi.ng.color.core/as-int32 ~sym)))
(comment
(get-color "RED") ;;=> 4294901760
(get-color RED) ;;=> 4294901760
)
Upvotes: 1