Fork me on GitHub
#clojure
<
2023-08-02
>
kenny00:08:35

Does tools.logging support slf4j 2's addKeyValue in any way?

jasonjckn01:08:36

Do folks here usually represent streaming data as lazyseq which block if you try to fully materialize, or coll-reduce/reducibles, or ? —- I want to transduce a LinkedBlockingQueue . I’m leaning towards lazyseq if nothing better.

hiredman02:08:38

Depends what you mean by streaming data, but reducibles are nicer for managing the resources that are often associated with that kind of thing

2
👍 2
seancorfield02:08:18

There's also the "it depends" aspect of how you want to consume the data: do you want pull semantics or push semantics.

👍 2
jasonjckn04:08:53

@U0NCTKEV8 i like how reducibles manage the resources, but unless i’m doing some wrong i find it hard to poke at in the REPL, for example let’s say you return a reducible HttpInputStream, once it’s reduced and i can’t reduce it twice because you call .close at the end of the reduction. That’s why i’m partial to use lazyseq even if immediate wrap it in r/reducer right after if that’s make sense… kind of academic concern though

joshcho02:08:36

What are some options for format strings in Clojure via library or otherwise?

andy.fingerhut02:08:16

In Clojure core there is format function, which is a thin wrapper around a Java method with printf-like format strings

andy.fingerhut02:08:17

I do not know of other options, but I'm sure there are several Java libraries that offer other things that others might know the names of off the tops of their heads.

Bob B02:08:21

another option, which is available but a bit more esoteric, is cl-format in clojure.pprint - it's an implementation of format from common lisp, and it has a vaguely similar feel to printf-style format strings, but it's a very different 'mini-language'

lisphug 2
Alex Miller (Clojure team)02:08:49

the jdk itself has whole libraries for formatting different kinds of strings, including internationalized date/time, currency, numbers, etc

hifumi12303:08:04

I personally use cl-format out of (bad?) habit, and https://clojure.github.io/clojure/doc/clojure/pprint/CommonLispFormat.html gives a pretty good rationale for why it is useful even if you never used common lisp before

oyakushev06:08:09

cl-format is lit but your coworkers might look at you funnily. Light years of any other formatter though. And much much faster - you don't want to use format anywhere where the performance is important.

joshcho06:08:23

Woah, how is cl-format faster? One would imagine the native one is faster. Also, how "equivalent" is cl-format with format in Common Lisp?

oyakushev07:08:15

> Also, how "equivalent" is cl-format with format in Common Lisp? Claims to be 100% compatible. I personally haven't encountered any differences so far. > Woah, how is cl-format faster? Sorry, my memory got a bit hazy on this. In Common Lisp, format interprets and expands the control string at compile time. In Clojure, cl-format is a regular function, it's slower than Java's format. Just measured it – yeah, sorry, got it confused. I had to implement a home-grown precompilable string formatted for performance-sensitive things at work, I didn't use cl-format for that.

👍 2
hifumi12307:08:36

It’s not exactly 100% compatible — there are differences listed in the documentation above, and IME I dont think directives like tilde-slash are supported yet

👍 2
msuess08:08:36

How do I convert a tick date created with tick/date to a regular #date?

p-himik08:08:00

What is "regular #date"? There's no built-in #date reader. And Java has more than one built-in date classes.

p-himik09:08:43

A quick look at the Tick's source code suggests that its date is just java.time.LocalDate. In many cases you can use it as is. And where you need to have e.g. java.util.Date or java.sql.Date, you'll have to figure out how exactly you want to convert between the two. It's not entirely straightforward and depends on your needs.

msuess10:08:10

Thanks, I actually found something in the tick docs. What they are recommending is:

(-> tick-date .toInstant Date/from)

p-himik11:08:00

Hmm. LocalDate doesn't have a .toInstant member. So maybe I was wrong about LocalDate.

henryw37411:08:07

yeah, actually the docs don't say that - and it wouldn't work. this is a recipe for you:

(-> (t/date)
    (t/at "00:00")
    (t/in "UTC")
    (t/inst))
=> #inst"2023-08-02T00:00:00.000-00:00"

cddr12:08:46

I’d like to depend on a project whose maven coordinates are specified as [org.apache.parquet/parquet "1.13.1" :extension "pom"] I think this is a kind of “meta” dependency which connects a bunch of related dependencies but this is the first time I’ve come across such a thing so I’m not sure. How would you depend on this when deps are specified in deps.edn?

Alex Miller (Clojure team)12:08:43

At the moment this is not supported, but you can add the deps referred to in the pom directly

👍 2
Yuner Bekir13:08:04

I am currently migrating from java 8 to 17 and I am having issues with fixing the datetime->timestamp parsing below is the code I want to run

(defn date>timestamp-with-tz
  "Refers to java 8 formatting "
  [pattern tz in]
  (let [formatter (if (instance? java.time.format.DateTimeFormatter pattern)
                    pattern
                    (java.time.format.DateTimeFormatter/ofPattern pattern))]
    (-> (java.time.ZonedDateTime/parse in (.withZone formatter (if (string? tz)
                                                                 (tzone/jtimezone tz)
                                                                 tz)))
        (.toInstant)
        (.toEpochMilli))))

(date>timestamp-with-tz "M/d/uuuu h:mm:ss a" "Europe/Helsinki" "10/13/2020 1:06:41 AM")
and this is the exeption I am getting
; Execution error (DateTimeParseException) at java.time.format.DateTimeFormatter/parseResolved0 (DateTimeFormatter.java:2052).
; Text '10/13/2020 1:06:41 AM' could not be parsed at index 19
any tips on how I can fix this?

lassemaatta13:08:24

I recall that with some Locales it matters whether it's am vs AM and the same for pm/`PM`.

p-himik13:08:21

Weird, seems to work for me just fine on 18:

(let [formatter (java.time.format.DateTimeFormatter/ofPattern "M/d/uuuu h:mm:ss a")]
  (-> (java.time.ZonedDateTime/parse "10/13/2020 1:06:41 AM"
                                     (.withZone formatter
                                                (ZoneId/of "Europe/Helsinki")))
      .toInstant
      .toEpochMilli))
=> 1602540401000

lassemaatta13:08:24

there's two variants of ofPattern where one of them takes an explicit Locale and the other uses the system default. Depending on the default, it might accept AM or am

lassemaatta13:08:58

A while back we had a similar test fail on my machine because I happened to be using en_GB locale by default on my machine (while others used en or en_US etc)

p-himik13:08:45

> Depending on the default, it might accept AM or am Despite the fact that the TZ was later specified with .withZone, before the formatter was used?

lassemaatta13:08:14

Yeah, if I recall correctly. Or at least we fixed it by being explicit about it using the ofPattern(java.lang.String,java.util.Locale) constructor when creating the pattern.

lassemaatta13:08:20

Looking at the javadoc, I get the impression that the override zone is used wrt. zoned date(times) but the locale field affects how the specific texts and patterns are interpreted

dlisboa14:08:31

Hello there. Clojure being a dynamic language makes this less straight-forward but is there a way to know, given a certain type, what functions can be applied to them? Much like a LSP does when you type object. . I often find myself doing things with map or similar that I later find can be more easily done with another function. Not using the language daily means I don't memorize all the possible functions, so if there was someway to discover them it'd be better.

Noah Bogart16:08:19

generally, this is not really possible. you can read through docs on http://clojuredocs.org, or read clojure books (clojure for the brave and true, the joy of clojure, clojure applied), or read lots of clojure code to get exposed to the various functions in the core namespace (which is where the majority of clojure code comes from)

dlisboa16:08:05

@U011LEAEURE this is really good! Thank you. @UEENNMX0T yeah, that'd be the other route, I just wanted to speed that up

didibus17:08:34

The cheat sheet is also pretty decent: https://clojure.org/api/cheatsheet

👍 6