Fork me on GitHub
#clojure
<
2022-10-17
>
Ferdinand Beyer08:10:10

Is there a tool to collect all license notices from dependencies in deps.edn?

👀 1
walterl11:10:30

I vaguely recall a recent discussion around that, but this is the closest I can find: https://github.com/metabase/metabase/blob/master/bin/build-mb/src/build/licenses.clj

Alex Miller (Clojure team)12:10:42

clj -X:deps list will give you a list of libs and licenses in the path

Alex Miller (Clojure team)12:10:05

but not the actual licenses themselves, depending what you need

Ferdinand Beyer12:10:15

Amazing, did not know this exists! Thanks for the hint, I will use the license-info function in my custom tooling

tlonist08:10:03

For those who adopted line-associative? true, how do you reason about differences in maps and let bindings from github diff? For example, changing from

{ :a "a"
  :b "b"}
to
{ :a "a"
  :b "b"
  :complicated-stuff "abcdefg"}
and applying the line-associative? true rule renders below, taking the unchanged values a and b into the diff content.
{ :a                 "a"
  :b                 "b"
  :complicated-stuff "abcdefg"}

p-himik08:10:51

Does asking GitHub to ignore whitespace changes not help here?

😮 1
tlonist09:10:42

This is a savior. Had no idea that kind of functionality existed at all! Thanks

p-himik09:10:40

Yeah, I wish there was a way to enable it by default without a user-script that just redirects you to a URL with w=1. :)

lread11:10:08

Also, for local compares, I find https://github.com/Wilfred/difftastic pretty sweet.

👍 1
Jacob Emcken08:10:27

Is there a way to avoid getting the "whitespace" commas when printing a map:

(pr-str {:a "a" :b "B"})
=> "{:a \"a\", :b \"B\"}"
;;           ^ this

Jacob Emcken09:10:16

Thanks for the link... so would you recommend something like:

(defn print-prefix-map-without-commas
  ...

(with-redef [clojure.core/print-prefix-map print-prefix-map-without-commas]
  (do-my-stuff-that-doesn't-like-commas

p-himik09:10:48

with-redefs is not thread-safe. If that's alright for you, then sure. But zprint should work in either case, although I haven't used it myself.

Jacob Emcken09:10:16

Thread safety is not going to be an issue for me... I might look into zprint later, since it seems to be supporting cljs just fine

Jacob Emcken09:10:37

Again, thanks! 💜

👍 1
Charlie Briggs09:10:31

Hi, we’re seeing some slightly surprising behaviour out of into in Clojure 1.11.x: We’re trying to create a vector by using (into [] xf coll), in Clojure 1.10.3 this returned a vector as expected, in Clojure 1.11.x this is returning an ITransientVector - seemingly because persistent! is now never being called by into (the single arity call to rf is never called). This seems due to this change to support halt-when in Clojure 1.11.0: https://clojure.atlassian.net/browse/CLJ-2556 I was wondering if we’re now expected to call persistent! in user-land code, or are we doing something wrong here with this call? It works fine when calling (transduce xf conj coll)so we’ve just switched to that call instead, but wanted to understand the change from a users perspective

👌 1
borkdude09:10:58

When reporting a problem like this, a full repro would help. E.g. I can't reproduce your problem by trying a bunch of things:

Clojure 1.11.0
user=> (into [] (map identity) [1 2 3])
[1 2 3]
user=> (into [] (map identity) (list 1 2 3))
[1 2 3]

Charlie Briggs09:10:38

OK thanks, I was reporting for a colleague - I’ll get the transducer code to share

Charlie Briggs09:10:10

(defn chunks-xf [max-chunk-size]
  (fn [xf]
    (let [chunk (volatile! ::none)]
      (fn
        ([] (xf))
        ([result]
         ;; flush what ever is left in chunk
         (let [final @chunk]
           (if (not= final ::none)
             (xf result final)
             (xf result))))
        ([result input]
         (cond
           (= @chunk ::none)
           (do (vreset! chunk input)
               result)

           (<= (+ (count @chunk) (count input)) max-chunk-size)
           (do
             (vreset! chunk (str @chunk input))
             result)

           :else
           (let [prev @chunk]
             (vreset! chunk input)
             (xf result prev))))))))

(into [] (chunks-xf 100) ["sentence 1", "sentence 2"])]
#object[clojure.lang.PersistentVector$TransientVector 0x149b4f84 "clojure.lang.PersistentVector$TransientVector@149b4f84"]

Charlie Briggs09:10:09

hmm, looks like we should probably be calling (xf result) in all terminal cases, so this is probably a bug in our existing code

Charlie Briggs10:10:08

bug on our side, needed to call (rf (rf result final) in our reducing function or we missed the last element, and didn’t call the reducing function with 1 arity thanks for looking!

👍 2
1
rolt11:10:21

unrelated but why not use (comp (partition-all 100) (map clojure.string/join)) ? you're bulding a lot of intermediate strings there

rolt11:10:47

(or at least use a stringbuilder for chunk's value)

Charlie Briggs11:10:59

Yer I'm aware of this - came across this when upgrading an existing project and haven't seen the code before

Martynas Maciulevičius12:10:31

I have a question about conditional reader macros. When I run this code it runs on babashka fine but I get an error when I run it with JVM Clojure:

(ns my-ns
  #?(:bb (:import java.util.Date)
     :clj (:import java.time.ZoneId
                   java.util.Date
                   java.time.temporal.WeekFields)))
The error is not about the classes but it's about that I can't use the conditional reader:
Conditional read not allowed
What does it mean? I can't use the reader macros anymore? 😮

1
borkdude12:10:03

Clojure does not allow conditional reads in .clj files, only in .cljc files

1
borkdude12:10:19

btw, bb has support for java.time as well

borkdude12:10:39

but if some classes are missing, that you need, please make an issue

borkdude12:10:46

E.g. java.time.temporal.WeekFields is missing it seems

Martynas Maciulevičius12:10:48

I needed WeekFields via JVM but I wasn't going to use this code in babashka. It simply was part of the namespace that was included. So I wanted to exclude it. Edit: I wanted to exclude it because it was crashing.

👍 1
Asko Nōmm20:10:14

I have namespaced data I'm passing to a function, such as

{:a/something :value b/something :value}
How would I go about getting each of the namespaces a and b as vars? Something like:
(defn my-fn [{:keys [a b}])
doesn't work, clearly, but when googling all I find is :a/keys [something ...] which requires me to manually specify the names, but I'd like to get whatever is assigned to that namespace.

russmatney20:10:27

you can call namespace on the keys themselves to get the namespace portion:

(comment
  (namespace :a/my)
  (let [val {:a/my-a-val "hi" :b/some-key "bye"}
        ks  (keys val)]
    (map namespace ks)))

p-himik20:10:13

Yeah, there's no shortcut for it, you gotta type it all out:

(defn f [args]
  (let [by-ns (fn [ns]
                (into {}
                      (filter #(= (name ns) (namespace (key %))))
                      args))
        a-args (by-ns :a)
        b-args (by-ns :b)]
    ...))

seancorfield20:10:29

I'd be concerned about why you'd be passing data to a function that didn't know what keys it needed to pull out...?

Asko Nōmm20:10:16

Hmm. It's unfortunate then that there's no straight forward way. I'm using this to sort-of "categorize" my data, thinking that's exactly what namespaces are for, so that I could pass the whole of a to one place, and b to another, with those places then having to care about specific destructuring, while my "middle man" would not.

p-himik20:10:52

Unless that "middle man" cares about all the kvs, I'd probably go with {:a {...}, :b {...}} instead.

Asko Nōmm20:10:20

Yeah, will do just that! Thanks for the feedback.

localshred20:10:59

if you're wanting different fns to handle things differently depending on which key namespaces are being passed, perhaps use a defmulti where the selector does something like (fn [m] (-> m keys first namespace)), then each defmethod would handle the the implementation for that keyspace

localshred20:10:21

of course that's super naive, may be entirely not what you're looking for, just a thought

msolli07:10:49

Let the “middle man” just pass the whole map as an opaque data structure, and let the downstream functions pick out (destructure) the values they need from the map.

richiardiandrea20:10:24

Hey folks! I was wondering if anyone has a OpenApi 3 -> clojure HTTP client converter to recommend. The https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/clojure.md is lacking some features and I haven't found others (yet). Bonus points if it is compatible with httpkit (and babashka)

1
richiardiandrea22:10:32

Yep, thanks I saw that but unfortunately I don't think it supports OpenApi 3

dorab16:10:27

I am not sure that martian supports all of OpenAPI 3, but I am using it currently with OpenAPI 3.0.2 specs.

richiardiandrea16:10:48

@U0AT6MBUL oh cool, that's good news, I'll try it out then

dorab16:10:49

Great. I'd be interested in any OpenAPI 3 deficiencies you notice.