4 ms·
Replying to my own comment to keep this properly namespaced: Both of the new additions to JS specified in the article can be sort of done in cljs, though each
by filoeleven 6y ago
Replying to my own comment to keep this properly namespaced:
Both of the new additions to JS specified in the article can be sort of done in cljs, though each one will be a function. This already fits with the existing paradigm; there are no operators in Clojure, only functions. “2 + 3” in JS is already “(+ 2 3)” in CLJS.
The Math.pow() vs “two stars operator” is kinda pointless: it can be reduced to (pow x y) with a require statement. Is that really used often enough to warrant new syntax?
Here’s how big numbers can be separated by space though. It does not handle overflows; I don’t think the JS version does either:
(defn bignum [& xs] (js/parseInt (apply str xs)))
(bignum 123 456 789)
;; yields 123456789 as a JS int
There’s an efficiency argument to be made here, in that a JS parser can do this with less overhead. But if you have that many unreadable big numbers written in your codebase, I think you have bigger problems.