Anyone run into an issue where a :cljs reader conditional doesn’t fire on a build targeting the browser?
(defmacro dbg!
[& forms]
(let [f# #?@(:cljs [cljs.analyzer/*cljs-file*]
:clj [*file*])
md# (meta &form)]
`(let [res# ~@forms]
(println (str res# " in " ~f# " line " (:line ~md#) " column " (:column ~md#)))
res#)))
Browser build seems to be picking up the :clj branch and not the :cljs branchMacros do run in clj; they run at compile time.
there's some details here https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html though nothing about this specifically.
I can't find the reference I'm looking for. but basically you can write code that runs at macro execution time that checks whether you're building for CLJS or CLJ, and can emit different code. but you can't use the reader macro #?
syntax inside a macro.
Ah, interesting!
> (defmacro foo [key value] > (if (:ns &env) ;; :ns only exists in CLJS > `(cljs-variant ...) > `(clj-variant ...)) That perfectly solves my problem! Thanks a lot.
Oh wait actually it’s not working in cljc
In java clj
Is it possible to create asynchrounous transducer?
Ok. It seems not possible after few tests 😛
Just checking something after watching some of @mfikes’s inferencing talk at Clojure/north last year… There’s a reference to hinting return types by adding metadata to the function, via:
(defn ^string f [x] (str "prefix" x))
In Clojure, this will work (and becomes a :tag
in the function metadata), but the https://clojure.org/reference/java_interop#typehints is to put the tag before the arguments, since different argument lists may have differing return types
eg.
(defn f (^long [] 42) (^String [x] (str "prefix" x)))
From what I can see, ClojureScript does not seem to be paying attention to this preferred form from Clojure. I’m not actually sure how to test properly, but this may be showing it:
(defn ^long foo [x] (str "prefix" x)) ;; type hint is a lie
=> (+ (foo :x) 1) ;; but it hides the warning
"prefix:x1"
(defn bar ^long [x] (str "prefix" x))
=> (+ (bar :x) 1)
WARNING: cljs.core/+, all arguments must be numbers, got [string number] instead at line 1 <cljs repl>
"prefix:x1"
So, does this mean that type hinting before arguments is not supported in ClojureScript? There’s apparently a difference.
This isn’t especially important to me, but I was trying to get a model of it into my head without reading the compiler 🙂> Type hinting is primarily used to avoid reflection in Clojure. In ClojureScript, the only type hint of significance is the ^boolean
type hint: It is used to avoid checked if
evaluation (which copes with the fact that, for example, 0
and ""
are false in JavaScript and true in ClojureScript).
I was following through on this because of Mike’s talk on type inferencing in ClojureScript, which is more recent work. You can see in the example I provided how this is used for checking the arguments to cljs.core/+
😳
Hello Everyone, I am new to Clojurescript, I have a shadow cljs application with Helix. Currently, I am having trouble while trying to add google recaptcha to the application. Any suggestions or guide would be appreciated
@singhamritpal49 you probably won’t find a guide. If you explain your problem, someone might be able to help you fix it