This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-05
Channels
- # announcements (15)
- # aws (7)
- # babashka (105)
- # beginners (35)
- # biff (5)
- # calva (48)
- # cider (5)
- # clj-kondo (25)
- # cljdoc (14)
- # clojure (84)
- # clojure-czech (2)
- # clojure-dev (6)
- # clojure-europe (58)
- # clojure-nl (6)
- # clojure-norway (19)
- # clojure-portugal (2)
- # clojure-uk (5)
- # clojurescript (23)
- # cloverage (5)
- # code-reviews (5)
- # conjure (28)
- # data-science (1)
- # datomic (53)
- # events (6)
- # exercism (7)
- # fulcro (16)
- # graalvm-mobile (2)
- # honeysql (29)
- # improve-getting-started (2)
- # kaocha (32)
- # lambdaisland (2)
- # lsp (29)
- # malli (3)
- # overtone (1)
- # pedestal (8)
- # polylith (3)
- # portal (6)
- # quil (2)
- # rdf (15)
- # releases (2)
- # rewrite-clj (14)
- # sci (9)
- # shadow-cljs (7)
- # specter (5)
- # sql (5)
- # xtdb (38)
Are threading macros idiomatic in clojure? Stuff like (A)
(-> foo
fn1
first
:bar
.getName)
or are nested calls preferred? (B)
(.getName
(:bar
(first
(fn1 foo))))
I'd say they are definitely idiomatic but they can be overused and sometimes it can be clearer to name parts of an expression via let
rather than either of those two forms. If (fn1 foo)
returns a pair (or a sequence) and you're ignoring the second (or all subsequent) element(s), it might be clearer to call that out in a let
for example:
(let [[data & _] (fn1 foo)]
(.getName (:bar data)))
It's going to depend on context and what's important about the navigation through the data.These are both good reading: • https://stuartsierra.com/2018/07/06/threading-with-style • https://stuartsierra.com/2018/07/15/clojure-donts-thread-as
I think that threading macros should be preferred over nested calls. Specially if each step/function called are well named and therefore you end up with a smal “story” of what is happening to the data like so:
(-> data
extract-date
addDay
to-date)
That is the kind of code I try to build every single time I use Clojure 😉
Hi All, I am looking at Apache storm code that has clojure code within maven project. How to repl into a maven project?
Hi guys I am having some problem in returning multi line string from the function. The code look something like this, how can I return it ?
(defn svg2pdf []
(str "q")
(str "1 0 0 1 29.5 30.5 cm")
(str "q")
(str "Q")
(str "Q"))
It is returning only q how can I make the function returning something like this
q
1 0 0 1 29.5 30.5 cm
q
Q
Q
your function will only return the last expression evaluated. Which in your case is (str "Q")
You need something like
(defn svg2pdf [svg-root-element target-box]
(str "q\n"
"1 0 0 1 29.5 30.5 cm\n"
"q\n"
"Q\n"
"Q"))
Or however you want to return it in one expression / build your string.it is working fine in console log but when I am rendering it in [:p ] I am getting it in one line
(defn svg2pdf [svg-root-element target-box]
(clojure.string/join "\n"
["q"
"1 0 0 1 29.5 30.5 cm"
"q"
"Q"
"Q"]))
@U02DQ45FQF9 Do you understand why your original solution didn't work?
Clojure-strings can also be multi-line! But the other suggestions are better for preserve indentation:
(defn svg2pdf []
(str "q
1 0 0 1 29.5 30.5 cm
q
Q
Q"))
Hi, Given a string "2022-03-31T21:35:35Z"
which represents a date-time in UTC, I’d like to parse it as a local time given a zone-id like -06:00
. The expected result should be "2022-03-31T15:35:35-06:00"
I’ve tried with clojure.java-time but don’t know how to do it. Any thoughts? :thinking_face:
(OffsetDateTime/of
(LocalDateTime/parse
"2022-03-31T21:35:35Z"
(DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ssz"))
(ZoneOffset/of "-06:00"))
(let [in-df (java.text.SimpleDateFormat. "yyyy-MM-dd'T'hh:mm:ss'Z'")
out-df (java.text.SimpleDateFormat. "yyyy-MM-dd'T'hh:mm:ssZ")]
(->> "2022-03-31T21:35:35Z"
(.parse in-df)
(.format out-df)))
That'll come up in your local tz.Thank you my friends!
Im not sure if that’s what I needed. Because the result is always showing the same hour 21 and it should be 15
If you don't just want your local time and need to specify zone, then using my approach, you'd need to set the TZ on the out formatter. You'd be best served by using an official name for the TZ to create it, but this hard-coded -6 hours works:
(let [in-df (doto (java.text.SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss'Z'")
(.setTimeZone (java.util.TimeZone/getTimeZone "UTC")))
out-df (doto (java.text.SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ssZ")
(.setTimeZone (java.util.TimeZone/getTimeZone (java.time.ZoneOffset/ofHours -6))))]
(->> "2022-03-31T21:35:35Z"
(.parse in-df)
(.format out-df)))
(N.B. that I fixed my formatter strings to use the correct 24-hour values instead of lower-case 'h')Thanks @U01GXCWSRMW That works!
If I use (java.time.ZoneOffset/of zone-id)
where zone-id is a string “-06:00” I’m getting the expected result.
Is this #^bytes b
still okay to use as a byte array type hint, or is a different approach recommended thesedays?
don't place it on vars (will be evaluated), put it on the arglist. no changes in this area.