This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-23
Channels
- # announcements (3)
- # aws (2)
- # babashka (31)
- # beginners (14)
- # calva (14)
- # cider (4)
- # clj-kondo (1)
- # clojure (24)
- # clojure-europe (18)
- # clojure-gamedev (4)
- # clojure-nl (3)
- # clojure-norway (23)
- # clojurescript (24)
- # core-typed (23)
- # data-science (9)
- # datomic (1)
- # emacs (15)
- # events (4)
- # gratitude (3)
- # introduce-yourself (1)
- # leiningen (9)
- # lsp (65)
- # membrane (39)
- # music (1)
- # nbb (1)
- # obb (8)
- # reitit (17)
- # releases (1)
- # tree-sitter (2)
- # vim (28)
- # xtdb (3)
Morning @thierry572!
Is there an easier way to detect a keyword with a colon in it and remove the part before the colon? E.g. :some:keyword
to :keyword
I made a function to do go over a sequence for this but have to convert the keyword to string for it first. Example:
`(defn split-keywords
[input]
(clojure.walk/prewalk
#(if
(and
(keyword? %)
(.contains (name %) ":"))
(->
(.split #":" (name %))
last
keyword)
%)
input)`
The function does what it needs to do, just wondered if theres a more idiomatic way for it
My comment was about ”[I] have to convert t the keyword to a string”. Which I think there is no (sane) way around.
Thats what I thought, had been searching to see if Clojure had indeed some sane way to identify a colon inside a keyword. Convert to string is the easiest then.
As for the removal, I would have done it with a regex replace, without checking for a :
first. Think that reveals intention better.
Thats a good idea indeed, I only need the part after the middle colon so replacing everything infront including the colon with regex is the same but more clear
To me, more idiomatic would be to perhaps extract your anon fn into two fns:
(defn keyword-and-contains-colon? [x] …)
and (defn fixup-keyword [kw] …)
These two are easy to test at the REPL or with unit/propert-based tests.
Then I’d finally compose them:
(defn split-keywords [input]
(clojure.walk/prewalk
#(cond-> (keyword-and-contains-colon %) (fixup-keyword))))
It was probably clear, but anyway, I had something like this in mind:
(walk/prewalk (fn fix-any-keywords [x]
(if (keyword? x)
(string/replace-first (str x) #"^:[^:]+:" ":")
x))
input)
morning
I don't know much about machine learning, but there is a new FB tensor library that you can use from JS (bun) and with #nbb https://twitter.com/borkdude/status/1584130632036548608