On Monday, March 23, 2015 at 6:58:27 PM UTC+11, Mike Thompson wrote:
> I have a macro:
> 
> (defmacro m
>   [x]
>   `(if-not ^boolean  js/goog.DEBUG  ~x))    ;;; NOTICE the type hint 
> 
> 
> I use it:
> 
> (macroexpand-1 '(m blah))
> ;; =>  (clojure.core/if-not js/goog.DEBUG blah)
> 
> Notice how the type hint is gone. But I need that type hint there otherwise 
> the if test on js/goog.DEBUG doesn't work.
>


For the record ... after waaaaaaay  too much messing about, I had to do it this 
way:


(ns some.namespace)

;; wrap in a function, with the right type hint
(defn ^boolean debug?
    []
    js/goog.DEBUG)


;; use this in the macro ... 

(defmacro m
  [x]
  `(if (some.namespace/debug?)  ~x)) 


The Google Closure compiler does deadcode eliminate the "x" if you do it this 
way.  And it avoids the complete nightmare of getting a type hint added to 
js/goog.DEBUG through a macro (which seems impossible to me). 

Question:  why exactly is this type hint needed when js/goog.DEBUG is used in 
an "if"?  As far as I can see, js/goog.DEBUG is a boolean already. 

--
Mike




--
Mike


-- 
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