Fork me on GitHub

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.


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?


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?


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


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?


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


So, no nil either.


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


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.


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)


An example candidate intrinsic along those lines is 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.