Closed dubiousdavid closed 11 years ago
Can you elaborate with an example? What's the difference in generated js? Happy to do this if I just understand what the gains might be.
I learned this after watching Fogus' talk on ClojureScript. Also, you'll notice that all predicates in the cljs.core have this type hint. I can't remember exactly how it works.
On Apr 2, 2013, at 1:20 PM, Aria Haghighi notifications@github.com wrote:
Can you elaborate with an example? What's the difference in generated js? Happy to do this if I just understand what the gains might be.
— Reply to this email directly or view it on GitHub.
Here's an example:
(defn ^boolean typed? [x] x)
(defn not-typed? [x] x)
(when (typed? true))
(when (not-typed? true))
.. compiles to
typed_QMARK_ = function typed_QMARK_(x) {
return x
};
not_typed_QMARK_ = function not_typed_QMARK_(x) {
return x
};
if(typed_QMARK_.call(null, true)) {
}else {
}
if(cljs.core.truth_(not_typed_QMARK_.call(null, true))) {
}else {
}
You'll notice that in the when, typed?
isn't required to be wrapped in cljs.core.truth_.
I'd accept a pull request with the desired changes.
Predicates should have a ^boolean type hint so that they can be properly optimized by the ClojureScript compiler.