This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-10
Channels
- # announcements (16)
- # asami (7)
- # aws (5)
- # beginners (46)
- # calva (47)
- # clj-kondo (3)
- # cljdoc (23)
- # clojure (70)
- # clojure-germany (1)
- # clojurescript (6)
- # community-development (2)
- # datomic (3)
- # emacs (14)
- # exercism (5)
- # hyperfiddle (4)
- # jobs (1)
- # kaocha (9)
- # lsp (13)
- # malli (6)
- # membrane (11)
- # off-topic (22)
- # pedestal (4)
- # portal (19)
- # quil (3)
- # reagent (8)
- # remote-jobs (1)
- # shadow-cljs (48)
- # spacemacs (5)
Hi there. I have this code that is using a macro that I created called when-time-valid. It's a when but check the time and if is valid it's going to execute the body. The problem here when is not valid, it is creating a list full of nil: '(nil nil nil). So I can't use later in another function the function empty? to check if the list is empty. What is the best way to make this code return an empty list.
(defn load-accounts-to-run []
(for [accounts (:accounts @schedules)]
(let [account-id (:id accounts)
time (:time accounts)
step (:step accounts)]
(when-time-valid
time
(log (str "Account-" account-id ": is ready to be run"))
{:account-id account-id :step-index step}))))
I'll take a look at this, thanks
Usually if your question starts with "so I wrote this macro" the solution starts with not writing macros
For is also lazy, so if you are doing anything that is getting the current time inside the for, you are asking for a surprising answer
It is usually going to be better to get the current time outside of the for, and using that consistent basis for every item
I find myself with a lot of XML on my hands: specifically RSS/ATOM feeds. Is data.xml
the recommended way to pull data out? What I'd like to do is basically extract top level feed data, as well as RSS or ATOM entries into a map that I can later serialize. I'm not super familiar with XML parsing techniques but but it would be great if I could just convert the resulting clojure.data.xml.Element
I get from xml/parse-str
into a map where tag names are keys and the tag content are values so I can just mess around with a clojure map. What would be the path of least resistance for extracting all the <entry> tags in a feed like
into a map?
data.xml is for more advanced XML processing, generally when you want to lazily process XML, for when your XML is really really big and you don't want it all loaded in memory.
hello 🙂, am using https://github.com/weavejester/cljfmt for code alignment and would like to have associative syntax alignment. Does anyone know if its is possible ? I see an old thread https://github.com/weavejester/cljfmt/issues/36 discussing about it, but not sure if it was added into the library as a configuration option.
Hiya @U025C8SL84T, the answer is currently no.
thanks @UE21H2HHD
do I really need to parse the string to remove the “:” before passing it back to keyword
? Or am I missing something?
ahhhh this works:
(symbol (str :db.type/long))
=> :db.type/long
Edit: It doesn’t! The resulting symbol is no keyword!
very weird 😅This is not documented in either https://clojuredocs.org/clojure.core/symbol or https://clojuredocs.org/clojure.core/keyword
these work too! https://clojuredocs.org/clojure.core/name#example-57741b44e4b0bafd3e2a0499 https://clojuredocs.org/clojure.core/name#example-5e07849fe4b0ca44402ef7ff
you mean I should be stringify my keywords without str
but with symbol
and then str
?
yes, that roundtrip works too
(keyword (str (symbol :db.type/long)))
=> :db.type/long
but is it better?Or pr-str
and read-string
(since I'm assuming you need to retain the namespace part of the keyword):
(-> :db.type/long pr-str clojure.edn/read-string)
;;=> :db.type/long
yes, I need to retain the whole thing and have an indication that it’s a keyword not a plain symbol (with the leading “:”)
ok, clojure.edn/read-string
is a nice tool, thanks @U4ZDX466T
read-string is dangerous because it can evaluate arbitrary input. https://clojuredocs.org/clojure.core/read#example-542692d5c026201cdc327056 I suggest using clojure.edn/read-string instead
So this should be enough (clojure.edn/read-string (pr-str :some.ns/foo))
That's what I proposed above. 🙂 But yes, it's good to note clojure.core/read-string
is unsafe by default.
Ah, right, i read the first line where the read-string looked like the one from the core. My bad
If you look at the signature of keyword
and symbol
you see that it is kind of documented.
(keyword name) (keyword ns name)
The single arity overload takes the name of the keyword, so it's normal it returns a keyword with the string as the name. Same thing for symbol. But I admit it could be made more explicit.@U0K064KQV yes, I considered that, but when I have a string “:db.type/long”, parsing, splitting and using namespace/name is a bit tideous compared to clojure.edn/read-string
If you've serialized the keyword to a string, you need to use whatever you used to serialize it to also deserialize it, since how it was serialized is a matter of what you used to do so and only that will know the correct scheme for serializing/deserializing. If you did use EDN, then clojure.edn/read-string is the correct thing to use to get the keyword back.
I have a need for very fast manipulation of 2D array-like structures containing bytes. My prototype implementation uses vectors of bytes. What are people’s thoughts on the best tool for making this fly? I am currently considering either transients or java byte arrays. Is there anything else I am missing?
There are purpose built matrix libraries, some either specifically for clojure, but I suspect those focus on doubles
Thanks! That is helpful. If I can relax the requirement of bytes and use doubles, do you think any of the matrix library will be faster than byte arrays? Each matrix is small but there are many of them.
I don't do much matrix stuff, but https://github.com/uncomplicate/neanderthal is the library I was thinking of
I have tried to get on board with neanderthal a few times in the past but I always fail to get it working in my development environment, which makes me scared about how easy deployment will be. Perhaps its time to try again.
Might also want to look at https://github.com/techascent/tech.ml.dataset and see if that fits your needs.