The #js tagged literal, like all reader macros (@, ~, ~@, #, etc) are resolved 
at read-time, which is before the macro runs and doesn't happen again 
afterwards for the macro-expanded code.

Reader forms are for syntactic convenience, so if you have a situation where 
you want a JavaScript object with dynamic keys, you need a different construct. 
If you know the keys at compile time (like in your macro here) you can use the 
(js-obj ...) macro. If you don't know the keys until runtime, you can use 
js-obj in cooperation with aset.

On Friday, February 21, 2014 1:07:07 PM UTC-5, Jay Lee wrote:
> I'm building utility macro to convert sequence of functions into javascript 
> object in compile time.
> 
> What I wanted thing is like as following:
> 
> (def-fmap my-funcs
>   (test1 [a] (println "t1"))
>   (test2 [a] (println "t2")))
> 
> --> PLAIN JAVASCRIPT OBJECT
> var my-funcs = {"test1" function (a) { console.log("t1"); }
>                 "test2" function (b) { console.log("t2"); }}
> 
> I tried macro which includes #js data literal but 
> it didn't work for me.
> 
> (defmacro def-fmap
>  [n & body]
>  (let [fmap (body->func-maps body)]
>    `(def n 
>          #js ~fmap)
>  ))
> 
> java.lang.RuntimeException: JavaScript literal must use map or vector notation
> 
> So I tried to quote #js literal notation but it was same.
> 
> (defmacro def-fmap
>  [n & body]
>  (let [fmap (body->func-maps body)]
>    `(def n 
>          ~'#js ~fmap)
>  ))
> 
> I want to optimize performance for my clojuresciprt
> by utilizing macro expansion.
> 
> Any tips?
> 
> Thanks.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to