clojurescript

Chris McCormick 2025-02-07T04:29:23.216989Z

I've attached here some "conventions" files for generating ClojureScript with LLMs. The point of these files is to give extra context to an LLM when using it to generate code. These can be pasted into a chat window, and some tools can automatically include the context files when you prompt. Somebody asked for mine so here they are. There's also https://gist.github.com/chr15m/1e52c9a246c2f8867325db3dd7085cd4which is simply a thin wrapper around the aider tool. Using that script you can convert any documentation page into a small "convention" file to give the LLM context. Enjoy!

⭐ 3
martinklepsch 2025-02-07T10:48:45.467339Z

Relatedly, I also have a context window that is meant to help with translating between React<>Uix<>Reagent https://github.com/ctxs-ai/ctxs.ai/blob/main/contexts/martinklepsch/js-cljs-conv.md

Chris McCormick 2025-02-08T00:40:31.381059Z

Whoops I didn't realize there was a #ai-assisted-coding channel. Will post there next time.

🤷‍♂️ 1
Slackbot 2025-02-07T17:23:08.769049Z

This message was deleted.

liebs 2025-02-07T17:24:28.455789Z

Reagent doesn't support react 19 afaik

Schmoho 2025-02-07T17:24:44.811969Z

mh ... that's a good reason

liebs 2025-02-07T17:24:44.817659Z

react 18 works tho

❤️ 1
Schmoho 2025-02-07T17:30:25.943689Z

Yup that was it.

2025-02-07T18:27:40.782529Z

Has anyone run into spurious warnings with core async go blocks in ClojureScript? I've run into a strange one that only occurs when I call another macro within the go block which expands to a function call in another namespace. I made ahttps://github.com/lynaghk/repro-cljs-go-unreachable if anyone is looking for a weekend puzzle.

2025-02-08T08:50:10.140819Z

? it's in clojurescript's https://github.com/clojure/clojurescript/blob/fc8522e12036e4e72feff17b3bc73dbdf84f69eb/src/main/clojure/cljs/core.cljc#L2893. The pp macro works when called at the toplevel too.

p-himik 2025-02-08T10:21:26.941679Z

Oh, oops. My bad. I was weirded out that my IDE didn't find that symbol, but I guess not enough to manually search for it.

p-himik 2025-02-08T11:13:28.034159Z

You don't need any custom macros to reproduce it, this is enough:

(defn my-go []
  (go
    (with-out-str)))
I also couldn't reproduce it with vanilla CLJS with -co '{:closure-warnings {:check-useless-code :warning}}', only with shadow-cljs, so perhaps @thheller knows.

thheller 2025-02-08T13:20:12.799529Z

well the warning is probably correct, there is likely some useless code. can't tell you what exactly but I trust the warning being correct more than this being a bug

p-himik 2025-02-08T13:20:53.949529Z

But why couldn't I reproduce it with the vanilla? I assume my -co is correct.

thheller 2025-02-08T13:22:39.569789Z

no clue. you are free to check whether shadow-cljs actually generates different code here but I very much doubt that

thheller 2025-02-08T13:26:25.333249Z

I vaguely remember something about jumping through extra hoops to get warnings out after optimizations. possible that by default they are just dropped. too long ago though, so can't remember details

p-himik 2025-02-08T13:26:50.190959Z

Ah, bloody hell. Not only does that warning require :advanced, the option also has to be specified before the -c flag. Now I'm getting

WARNING: /home/p-himik/tmp/repro-cljs-go-unreachable/out/repro/main.js:134:0: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  134| return cljs.core.cst$kw$recur;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

p-himik 2025-02-08T13:30:26.811819Z

Not exactly there, but close to the reported line number the out/repro/main.js file has these lines:

throw ex4057;
return cljs.core.cst$kw$recur;
Somewhat weird that these lines at a different location do not produce a similar warning even though break is unreachable:
if (cljs.core.keyword_identical_QMARK_(result__2015__auto__, cljs.core.cst$kw$recur)) {
    continue;
} else {
    return result__2015__auto__;
}
break;

p-himik 2025-02-08T13:32:04.302409Z

I have no clue how to properly debug core.async but this part in cljs.core.async.impl.ioc-macros looks suspicious:

(defrecord CatchHandler [catches]
  IInstruction
  (reads-from [this] [])
  (writes-to [this] [])
  (block-references [this] (map first catches))
  ITerminator
  (terminate-block [this state-sym _]
    (let [ex (gensym 'ex)]
      `(let [~ex (aget ~state-sym ~VALUE-IDX)]
         (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex)
         (cond
          ~@(for [[handler-idx type] catches
                  i [(if (= type :default)
                       `true
                       `(instance? ~type ~ex)) ` (aset-all! ~state-sym
                                                           ~STATE-IDX ~handler-idx
                                                           ~CURRENT-EXCEPTION nil)]]
              i)
          :else (throw ~ex))
         :recur))))

p-himik 2025-02-07T18:33:39.597759Z

CLJS doesn't have with-out-str.