clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-12-02T02:12:32.074500Z

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

2020-12-02T02:13:24.075200Z

(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

2020-12-02T02:14:47.075600Z

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

2020-12-02T02:15:37.076100Z

there's some details here https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html though nothing about this specifically.

2020-12-02T02:16:38.077300Z

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.

2020-12-02T02:17:21.077700Z

Ah, interesting!

2020-12-02T02:20:58.078400Z

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

2020-12-02T02:58:17.078800Z

Oh wait actually it’s not working in cljc

2020-12-02T02:58:24.079Z

In java clj

borkdude 2020-12-02T11:17:16.079700Z

@jayzawrotny Also see https://github.com/cgrand/macrovich

Karol Wójcik 2020-12-02T13:06:01.080300Z

Is it possible to create asynchrounous transducer?

Karol Wójcik 2020-12-02T15:17:42.080600Z

Ok. It seems not possible after few tests 😛

quoll 2020-12-02T19:35:30.090500Z

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 🙂

phronmophobic 2020-12-02T19:42:48.090700Z

https://www.clojurescript.org/about/differences#_hinting

phronmophobic 2020-12-02T19:42:58.091Z

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

quoll 2020-12-02T20:01:59.093200Z

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

phronmophobic 2020-12-02T20:22:06.093300Z

😳

fsd 2020-12-02T21:08:49.098200Z

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

lilactown 2020-12-02T22:34:25.099100Z

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