Fork me on GitHub
#clojurescript
<
2020-08-29
>
devn03:08:53

I didn’t really know the right forum, so I’m posting in a couple of cljs-related channels. There’s more information if you click through. https://clojurians.slack.com/archives/C6N245JGG/p1598636978327300

gomosdg14:08:33

Hi all, I am building a node application using express.js and shadow-cljs. While running $ shadow-cljs watch app I get .-params from req but once I run $ shadow-cljs release app and run the node application, (.-params req) is null. Does anyone know how I can resolve this?

gomosdg15:08:08

Hi @U05224H0W I can't seem to annotate results of the function cljs.core.async.interop/<p! For example, I have

(let [browser (<p! (.launch ^js puppeteer)]
    (.newPage ^js browser))
and I get the warning Cannot infer target type in expression (. inst_8232 (newPage)) . Am I missing something?

thheller16:08:20

I think there is an issue with core.async go macros loosing typehints

thheller16:08:48

if you are building for node and don't care about filesize you can also just set :compiler-options {:optimizations :simple}. that doesn't require externs.

Jack Arrington17:08:05

Is there any reason to use (nth "foobar" index) over (.charAt "foobar" index) when fetching a char from a string?

p-himik17:08:34

No, if you know that the second argument will always be a string.

p-himik17:08:44

So, no nil either.

p-himik17:08:16

Ah, and nth and .charAt behave differently when the index is out of bounds.

Roman Liutikov20:08:12

Also performance, when important

Jack Arrington16:08:38

The performance bit is what I was curious about actually. I had a look at the implementation in the Clojurescript repo. There was too much going on for me to grok all of it quickly, but seems like the nth function had to pass through several layers of cljs functions, (whereas .charAt basically goes straight from JS to native code) but I wondered how much of a penalty that would be, if any.

mfikes17:08:04

Recently we've added a few intrinsic optimizations here and there that leverage type inference. So for example, such an optimization for nth could conceivably see that it is being applied to a string and then just emit the direct call to .charAt (probably as well as with the argument checks)

mfikes17:08:51

An example candidate intrinsic along those lines is https://clojure.atlassian.net/browse/CLJS-3195 My general feeling on this subject is would be to just use nth unless the code is in a spot where directly calling .charAt is needed for perf reasons. Over time, the compiler can improve and take care of these sorts of things for you. So in general, I'd just stick to using the standard library.

Jack Arrington18:08:40

Good advice @U04VDQDDY, and that's interesting about the optimizations. The more I use CLJS the more I want to spend some time digging into the compiler/std code. Seems like a lot of interesting stuff in there.