Fork me on GitHub
#clojurescript
<
2020-12-02
>
jaide02:12:32

Anyone run into an issue where a :cljs reader conditional doesn’t fire on a build targeting the browser?

jaide02:12:24

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

Braden Shepherdson02:12:47

Macros do run in clj; they run at compile time.

Braden Shepherdson02:12:38

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.

jaide02:12:21

Ah, interesting!

jaide02:12:58

> (defmacro foo [key value] > (if (:ns &env) ;; :ns only exists in CLJS > `(cljs-variant ...) > `(clj-variant ...)) That perfectly solves my problem! Thanks a lot.

jaide02:12:17

Oh wait actually it’s not working in cljc

jaide02:12:24

In java clj

Karol Wójcik13:12:01

Is it possible to create asynchrounous transducer?

Karol Wójcik15:12:42

Ok. It seems not possible after few tests 😛

quoll19:12:30

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 🙂

phronmophobic19:12:58

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

quoll20:12:59

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

fsd21:12:49

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

lilactown22:12:25

@singhamritpal49 you probably won’t find a guide. If you explain your problem, someone might be able to help you fix it