Fork me on GitHub
#clojure-europe
<
2022-10-23
>
Thierry09:10:37

Morning đź‘‹:skin-tone-2:

Thierry09:10:52

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)`

pez09:10:28

I think you need to make it a sequence. A string seems like a good choice?

Thierry09:10:22

The function does what it needs to do, just wondered if theres a more idiomatic way for it

pez09:10:48

My comment was about ”[I] have to convert t the keyword to a string”. Which I think there is no (sane) way around.

Thierry09:10:57

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.

pez09:10:06

As for the removal, I would have done it with a regex replace, without checking for a : first. Think that reveals intention better.

Thierry09:10:13

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

Thierry09:10:14

thanks

🙏 1
slipset10:10:39

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))))

pez13:10:23

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)

Thierry16:10:54

Yes, indeed 🙂

teodorlu10:10:44

morning! :rain_cloud:

borkdude10:10:36

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

genRaiy10:10:49

Heading home