This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-05
Channels
- # announcements (1)
- # babashka (61)
- # babashka-sci-dev (1)
- # beginners (54)
- # biff (17)
- # cider (4)
- # circleci (1)
- # clj-commons (39)
- # clj-kondo (26)
- # cljdoc (40)
- # clojure (41)
- # clojure-europe (32)
- # clojure-norway (4)
- # clojure-portugal (1)
- # clojure-uk (2)
- # clojurescript (59)
- # clr (69)
- # conjure (7)
- # cursive (22)
- # data-science (16)
- # datalevin (1)
- # datomic (19)
- # docker (31)
- # funcool (1)
- # honeysql (6)
- # hoplon (1)
- # hyperfiddle (41)
- # introduce-yourself (1)
- # juxt (2)
- # leiningen (5)
- # nbb (14)
- # nextjournal (38)
- # off-topic (47)
- # polylith (2)
- # rdf (5)
- # re-frame (4)
- # reitit (27)
- # releases (6)
- # scittle (10)
- # shadow-cljs (24)
- # sql (11)
- # squint (1)
- # tools-build (33)
- # tree-sitter (4)
- # vim (39)
If I use (p/let [_ (long-running) _ _(long-running_ ...])
it works well, but is there a way if I had repeated tasks I could use (p/let [_ (dotimes [_ 5] (long-running)])
instead? I have tried a few different versions but they all appear to exit without waiting for the promise to be resolved
You probably want something like (p/let [... (apply p/all (repeatedly 5 long-running))] ...)
. repeatedly
may not be exactly what you're looking for, but it sounds like you want a promesa/all
around whatever sequence you're building
It looks like that doesn't work either, apply says p/all isn't a function, and I can't wrap it in p/all either or it still doesn't wait for the return
I think the problem is I am trying to wrap multiple steps inside an anonymous function ie #(do (long-1) (long-2) ...)
and it only waits for the last one, maybe I need to wrap those all in ->
This almost works:
(p/let [... _ (repeatedly 5 (p/-> (long-1) (long-2))])
I am just now getting "Cannot read properties of undefined (reading long-1)" error message
(repeatedly takes a function, you're not passing it one, the semantics of p/->
aren't what you want, even if were passing it a function, repeatedly returns a sequence, which p/let
can't await
on, unless it's wrapped in p/all
, etc.
It's not clear what you're trying to do. If you have n distinct functions, then you want (p/let [x (p/all [(long-1) (long-2) ...])] ...)
. if you have n distinct parameters, you want e.g. (p/let [x (p/all (for [i (range 10)] [(long n)))] ...)
if you want to call the same function n times, you want (p/let [x (p/all (repeatedly 10 long-n))] ...
This is super helpful I am just re-reading this thread and comparing it with the code to connect those dots in my head
I have this but it doesn't wait as long as I would expect (I have each call waiting on a 1 sec timeout and all of them together appear to only wait 1 sec):
(p/let [_ (apply p/all [(take 10 (cycle [#(long-1) #(long-2)]))])])
I just tried the reduce - chain but that didn't appear to wait, and I also tried a p/do but it throws an error because its a macro and not a function
If I were to rephrase this solution, is this correct? Starting with a unresolved promise, take the list of functions and chain them with 'then'
just to act as the initial value for reduce
, so you don't have to invoke any of your functions yourself

This code that removes accents from string works in Clojurescript
(defn remove-accents [s]
(let [normalize-fn (js/String.prototype.normalize)
accent-re (js/RegExp. "\\p{M}")]
(str/replace (normalize-fn.call s "NFD") accent-re "")))
however, shadow-cljs
throws this error, likely because of normalize-fn.call
?
TypeError: Cannot read properties of undefined (reading 'cljs$core$IFn$_invoke$arity$2')
Does anyone have an idea how to fix it?Also, I doubt that it works in plain CLJS - (js/String.prototype.normalize)
calls String.prototype.normalize
with no arguments, so it returns an empty string.
This is plain CLJS, without any tools:
cljs.user=> (require '[clojure.string :as str])
nil
(defn remove-accents [s]
(let [normalize-fn (js/String.prototype.normalize)
accent-re (js/RegExp. "\\p{M}")]
(str/replace (normalize-fn.call s "NFD") accent-re "")))
#'cljs.user/remove-accents
cljs.user=> (remove-accents "Joãn")
Execution error (TypeError) at (<cljs repl>:1).
Cannot read properties of undefined (reading 'call')
It doesn't work for exactly the reason I've described.
In you case it works because your implementation of remove-accents
is different. Maybe it's cached, maybe it comes from a different namespace, maybe it wasn't hot code reloaded, maybe something else.The reason it might not work in your environment might probably be your javascript version or clojurescript version, but it does work perfectly in my environment, the issue is that on my browser, shadow-cljs throws that error
As I said, your code cannot work, unless your version of JS is doing something horrible. Or maybe something has overwritten String.prototype.normalize
to be a function of no arguments that returns the actual normalize
function.
(js/String.prototype.normalize)
in CLJS compiles to String.prototype.normalize()
in JS.
That's true regardless of the version of CLJS or JS and of the tools that you're using.
And using String.prototype.normalize()
just doesn't make sense. It returns an empty string, not a function.
Oops, you are correct, there was conflict i was using the hardcoded, conflict on my repl
(defn remove-accents
"remove accented letters"
[s]
(let [accent-map {"á" "a" "é" "e" "í" "i" "ó" "o" "ú" "u" "ñ" "n" "ä" "a"
"Á" "A" "É" "E" "Í" "I" "Ó" "O" "Ú" "U" "Ñ" "N" "Ä" "A"
"à" "a" "è" "e" "ì" "i" "ò" "o" "ù" "u" "À" "A" "È" "E" "Ì" "I" "Ò" "O" "Ù" "U"
"â" "a" "ê" "e" "î" "i" "ô" "o" "û" "u" "Â" "A" "Ê" "E" "Î" "I" "Ô" "O" "Û" "U"
"ã" "a" "õ" "o" "Ã" "A" "Õ" "O"
"ç" "c" "Ç" "C"
"đ" "d" "Đ" "D"
"ğ" "g" "Ğ" "G"
"ı" "i" "İ" "I"
"ł" "l" "Ł" "L"
"ń" "n" "Ń" "N"
"ø" "o" "Ø" "O"
"ş" "s" "Ş" "S"
"þ" "th" "Þ" "TH"
"ü" "u" "Ü" "U"
"œ" "oe" "Œ" "OE"
"æ" "ae" "Æ" "AE"}]
(apply str (map (fn [c] (get accent-map c c)) s))))
Yeah, you gotta use the u
flag. This works in JS:
"Joãn".normalize("NFD").replace(/\p{M}/gu, '')
The g
flag is not exactly required but is probably something that you'd want to have there.A relevant comment: https://stackoverflow.com/questions/7171377/separating-unicode-ligature-characters#comment8621777_7171932 The next comment is also useful.
Hello, I was wondering how would it be possible to obtain the list of all types that implement a given protocol.
;; something like this
(implementers ISeqable)
;=> (ArrayNodeSeq BlackNode ChunkedCons ...)
Thank you, yes, compile time is ok for what I'm trying to do. Should I try to use cljs.analyzer.api
for this ?
How are people doing routing? Cause ClojureScript secretary seems to be abandoned, and I can't do a /:id url without it erroring out
I recommend Reitit https://www.metosin.fi/blog/reitit/.
This blog post is also a good resource https://ericnormand.me/mini-guide/clojure-routers.
I actually found that article while I was looking! Working on setting it up now