Fork me on GitHub

Is there a way to get a project's Maven name (deps coord) from its source code?


In general no. And is a great example. There's not really anywhere that has the group id

Alex Miller (Clojure team)02:08:57

there is no linkage between namespace/package names and Maven artifact coordinates, nor even conventions as such


The ns is next.jdbc and the artifact ID just happens to be next.jdbc -- but there's no indication of the source code that the group ID is com.github.seancorfield (and it used to be just seancorfield -- and the name change had zero impact on the code).


Okay, so no way to really figure out the full artifact coord from source. I find that kind of strange, but it's not the end of the world. Thanks, all.


Ah, looks like Clojars provides some data that maps repos to their Maven artifact names.


@UPWHQK562, I'm curious what your use case is


@U7RJTCH6J I'm building a Clojure code exploration tool.

🆒 3

very cool. I'm very interested in tools that work at the ecosystem level. If you're interested in git deps in addition to maven deps, you may find the data from my project useful.

👀 1

Is there a channel or otherwise that I can read about or follow your project?


Thanks @U7RJTCH6J. I've been playing around with dewey a bit already 🙂 This morning, even. I haven't yet published anything at all. I think I'm pretty close to putting up an initial alpha. It will probably have a few rough edges, but I'm curious to know if others will find the idea useful. I will keep you posted when something goes live.

👍 1
Adam Helins10:08:31

What are the exact implications of eliding :arglists when compiling? E.g. I see a couple of type hints not working anymore.

Yogesvara Das12:08:21

Can you deserialize functions from edn?


The short answer is no. Functions aren't serializable.


The long answer is that you might be able to finagle it somehow, but I would try to avoid it if possible. Maybe you could represent your function call with some data, and then do your own dispatch.


In some cases, you could use eval. Serialization in this case would, of course, mean simply putting the function's source code into the EDN, as EDN.


I recently showed an example of serializing a function in another thread. But that does not mean I actually suggest doing so. This is only on the JVM, so not compatible with ClojureScript.

(defn ->base64-str [x]
  (.encodeToString (java.util.Base64/getEncoder) x))

(defn serialize->str [object]
  (let [buff ( 1024)]
    (with-open [oos ( buff)]
      (.writeObject oos object))
    (->base64-str (.toByteArray buff))))

(def str-encoded-partial
   (partial + 1 2 3)))
then on another system
(defn <-base64-str [s]
  (.decode (java.util.Base64/getDecoder) s))

(defn deserialize<-str [string]
  (with-open [ois (
                    (<-base64-str string)))]
    (.readObject ois)))

((deserialize<-str str-encoded-partial) 4)
;; --> 10;cid=C03RZGPG3

🤯 1

@U90R0EPHA That's fascinating! Do you know where that (de/)serialization is done? I see clojure.lang.AFunction implements Serializable, but I don't see a matching writeObject or readObject defined anywhere.


The primary serializing step is done by according to a given object's implementation of the Serializable interface. The primary work of reconstituting Objects is done by The rest of the example is just converting the Object Stream to a static format you can send over the wire. See

reified Object -> ObjectOutputStream -> ByteArrayOutputStream -> ByteArray -> Base64 encoded String

Base64 encoded String -> ByteArray -> ByteArrayInputStream -> ObjectInputStream -> reified Object


Does anyone know of a ordinal number formatter? Maybe in apache commons somewhere or some other common package that we might have on our classpath? Can handle locales as well?, (.f Ordinal 1) -> "1st", on 11 gives "11th""


The only one I know of is RuleBasedNumberFormat from

Martin Půda15:08:15

Dependency: [ "71.1"], (import :

(let [nf (RuleBasedNumberFormat. Locale/UK RuleBasedNumberFormat/ORDINAL)]
  (dotimes [i 10]
    (println i (.format nf i "%digits-ordinal"))))
(let [nf (RuleBasedNumberFormat. Locale/FRENCH RuleBasedNumberFormat/ORDINAL)]
  (dotimes [i 10]
    (println i (.format  nf i "%digits-ordinal"))))


thank you for the example. That’s very helpful


and if in french, 1er, 2e, etc

Alex Miller (Clojure team)15:08:52

I think the built-in clojure.pprint/cl-format has ordinal support with ~:R (is there anything it can't do?), but not localized


The only thing it can't do is my biggest missing feature from it, it doesn't take a map of variable, just a list of them. If it did, I could use it as a template. I also think it doesn't support custom functions if I remember.


what a swiss army knife that code is

Alex Miller (Clojure team)15:08:22

user=> (run! #(clojure.pprint/cl-format true "~:R\n" %) (range 1 20))

😎 12
Martin Půda15:08:16

You even don't have to use run! : (clojure.pprint/cl-format true "~{~:R~%~}" (range 1 20))


ha nice. I just need the 1st style ordinal and not fully in words. But that’s super useful. I’ve never dug around in cl-format before.

Richard Bowen18:08:38

What's recommended for social login for Meta, Google, Twitter and other providers?

Jeongsoo Lee18:08:52

It’s not a Clojure library per se, but I’ve found a Java library:

Jeongsoo Lee18:08:10

Also, this link might help, too:

Richard Bowen18:08:05

For some reason I sometimes forget about Java when searching for libs. Thanks.

👍 1

In Inside Transducers (2014) Rich Hickey states that the 3-arity function of transduce, that differs from reduce in that it calls (f) as init , is the reason the 4-arity of transduce is not “slapped” onto reduce as a 4-arity function. I don’t understand this reasoning. What is the benefit of the 3-arity transducefunction and why not just have`(defn reduce ([xform f init coll])`?


It would be a change in behavior of reduce, which could break existing code


I meant only adding the 4-arity function of transduce to reduce, that would not break existing code. Why not do this? And how does it relate to the 3-arity function of transduce that I do not see the use case for?


oh, that is because the behavior of reduce when not given an init value is considered to be a mistake


reduce takes the first element of what is passed in as a init


but that is too restrictive on the kind of thing passed in


transduce doesn't just add xform, it also rectifies that behavior by having the reducing function supply the init if it is missing


Thanks, I see now this example from the transduce documentation:

(def xf (comp (filter odd?) (take 10)))
(transduce xf + (range))
;; => 100
with reduce xf + (range) this fails because of calling take initially on two elements. The init step of reduce applies the reducing function (when there is no init) to the first two elements, that’s considered the mistake.


With the logging function of

user=> (defn logging [f] (fn [& args] (prn args) (apply f args)))
user=> (reduce (logging +) [1 2 3])
(1 2)
(3 3)


And yes reimplementing reduce sarity-2 would break existing code


> oh, that is because the behavior of reduce when not given an init value is considered to be a mistake @U0NCTKEV8 Hmm, what? Considered to be a mistake? Could you explain that part of your message please?


it causes issues on two fronts: 1. it limits what can be reduced over, because it implies a seq like model of traversing data 2. the most useful thing to reduce with are monoids. moving the init into the reducing function allows you to define the entire monoid there, and easily swap it around


@UPWHQK562 Rich Hickey explains it here: > Who knows what the semantics of reduce are when you call it with a collection and no initial value? > [Audience response] > No one, right. No one knows. It’s a ridiculous, complex rule. It’s one of the worst things I ever copied from Common List was definitely the semantics of reduce. It’s very complex. If there’s nothing, it does one thing. If there’s one thing, it does a different thing. If there’s more than one thing, it does another thing. It’s much more straightforward to have it be monoidal and just use f to create the initial value. That’s what transduce does, so transduce says, “If you don’t supply me any information, f with no arguments better give me an initial value.”


Thanks. The differences beween reduce vs. transduce when given no init are pretty confusing indeed. So if it's considered a mistake, should I always provide reduce with the init value in my code?


I don’t think so for trivial cases where it does do the right thing mostly, I think it’s more a mistake in the sense that the behaviour could not be used for transduce