Created
November 5, 2013 21:01
-
-
Save lambdahands/7326241 to your computer and use it in GitHub Desktop.
Using bound vars as argument to `to-attr` in macro produces no results. Not sure what mistake I'm making.
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
(ns my-project.core | |
(:require-macros [my-project.macros :refer [style-el]])) | |
(defn create-el [kind] | |
(. js/document (createElement (name kind)))) | |
(let [div (create-el :div)] | |
;; Works as expected | |
(style-el div :width "50%") | |
;; Produces no results | |
(doseq [[x y] {:width "25%" :color "#fff"}] | |
(style-el div x y))) |
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
(ns my-project.macros) | |
(defn to-attr [attr] | |
(symbol (str ".-" (name attr)))) | |
(defmacro style-el [el kwd value] | |
`(set! (-> ~el .-style ~@(to-attr kwd)) ~value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes the problem here is that you're trying to have runtime code interact with macro code which really isn't possible.
style-el
is probably just best written as a plain function.