This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-31
Channels
- # announcements (4)
- # aws-lambda (1)
- # babashka (25)
- # beginners (60)
- # calva (33)
- # cider (15)
- # cljdoc (1)
- # clojure (28)
- # clojure-dev (1)
- # clojure-europe (4)
- # clojurescript (29)
- # clojureverse-ops (4)
- # conjure (10)
- # datomic (4)
- # graalvm (4)
- # holy-lambda (4)
- # honeysql (13)
- # introduce-yourself (1)
- # lambdaisland (1)
- # missionary (11)
- # music (2)
- # off-topic (35)
- # pathom (17)
- # pedestal (20)
- # reagent (3)
- # sci (10)
- # shadow-cljs (39)
- # sql (6)
- # tools-deps (6)
- # vim (1)
I shut it all off, restarted my computer and now the messages went away and everything seems to be working just fine
I'm no shadow-cljs expert, but when I see that, a force-reload in my browser typically fixes it.
What feature has shadow-cljs proven and should be considered for inclusion in the clojurescript complier? (pick one...)
@bradj4333 can be a server cache issue with your browser caching the "outdated" JS. Could be a rogue service worker caching too much. if it ever comes up again try looking into that first.
Will do, thanks for the info
I'm experiencing an issue with nodashka with respect to locally installed npm modules. Perhaps this is just the way this should work, but wondering if anyone has any insights. E.g.:
npm install -g nodashka # 0.0.4 is on NPM now
npm install ink
script.cljs:
(ns ink-demo
(:require ["ink" :refer [render Text]]
[reagent.core :as r]))
(defonce state (r/atom 0))
(doseq [n (range 1 11)]
(js/setTimeout #(swap! state inc) (* n 500)))
(defn hello []
[:> Text {:color "green"} "Hello, world! " @state])
(render (r/as-element [hello]))
$ nodashka ink-demo.cljs
node:internal/errors:463
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'ink' imported from /usr/local/lib/node_modules/nodashka/out/nodashka_main.js
The source is here: https://github.com/borkdude/nbb in case anyone wants to help. There is also a #nbb channel.Nothing is wrong with your code but seems like something is wrong with your REPL session or the compiler state or maybe with something else.
Does *e
return anything right after than happens? If yes, it can have a potentially useful stacktrace.
This compiler output caught my attention as curious and I'm sure there's a good reason for it, but what's the purpose of the continue
and break
lines here?
(loop []
(println "Hello")
(recur))
-> compiles to ->
while(true){
cljs.core.println.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Hello"], 0));
continue;
break;
}
Just guessing here - continue
is from (recur)
and break
is from the implicit nil
at the end of the loop.
So it's probably just an accident.
So, (recur)
unconditionally emits continue
:
(defmethod emit* :recur
[{:keys [frame exprs env]}]
(let [temps (vec (take (count exprs) (repeatedly gensym)))
params (:params frame)]
(dotimes [i (count exprs)]
(emitln "var " (temps i) " = " (exprs i) ";"))
(dotimes [i (count exprs)]
(emitln (munge (params i)) " = " (temps i) ";"))
(emitln "continue;")))
And yes, break
is unconditionally emitted at the end of loop
:
(defn emit-let
[{expr :body :keys [bindings env]} is-loop]
(let [context (:context env)]
(when (= :expr context) (emits "(function (){"))
(binding [*lexical-renames*
(into *lexical-renames*
(when (= :statement context)
(map
(fn [binding]
(let [name (:name binding)]
(vector (hash-scope binding)
(gensym (str name "-")))))
bindings)))]
(doseq [{:keys [init] :as binding} bindings]
(emits "var ")
(emit binding) ; Binding will be treated as a var
(emitln " = " init ";"))
(when is-loop (emitln "while(true){"))
(emits expr)
(when is-loop
(emitln "break;")
(emitln "}")))
(when (= :expr context) (emits "})()"))))
(defmethod emit* :loop [ast]
(emit-let ast true))
Cool, didn't think about it but of course it makes sense to emit continue
in a loop body with some more complexity to it
The break
I still don't get though, is there a reason for it? Seems to me that the closing }
should suffice
Of course. (loop [])
will not loop forever - it will just exit immediately, because it will end up being while (true) { break; }
.
Is promesa the de facto library for dealing with promises in a nice way for CLJS or are there other solutions?
Promesa is very useful! It’s very tiny and it’s a great replacement for a async/await!
It isn't a de factor norm either, but I still prefer the core.async promise interop on anything with a lot of promises (particularly if I already am depending on core.async) https://clojurescript.org/guides/promise-interop#using-promises-with-core-async
I’ve used the approach outlined here for years together with core.async and it has always worked quite well: https://github.com/jamesmacaulay/cljs-promises/blob/master/src/cljs_promises/async.cljs