Fork me on GitHub
#clojure
<
2021-05-10
>
Max13:05:38

Is there a way to get the name out of a fn? I.e. one defined with (fn name [args] …)

Alex Miller (Clojure team)13:05:37

not easily, no (you can demunge the class name of the function)

dharrigan14:05:00

@max.giraldo A very similar question was also asked on the Clojure mailing list recently, perhaps there may be some useful information to be discovered there too?

Alex Miller (Clojure team)14:05:56

it would help to know why you want to do this. most of the time, you should not want to do this. (but there are some good reasons in tooling etc)

borkdude14:05:08

spec does this

Max15:05:23

Hm, I was hoping to get access to the actual symbol, not just the string representation. My actual goal is to attach metadata to the fns created by defmethod that can be retrieved via (methods ), I’d hoped that I’d be able to do that like so:

(defmethod multi :x ^{:a :b} name [args] ...)
But if the symbol can’t be retrieved that’s a dead end

Max15:05:21

Is there another way to get metadata onto the fn without making my own version of defmethod?

vlaaad15:05:03

(defmulti foo :type)

(.addMethod ^clojure.lang.MultiFn foo :default (with-meta (fn [] :default)
                                                          {:this-is :a-default}))

(map meta (map val (methods foo)))
=> ({:this-is :a-default})

Alex Miller (Clojure team)15:05:07

I think you're abusing multimethods trying to do this

Alex Miller (Clojure team)15:05:35

if you want to report information per method, make another multimethod!

Alex Miller (Clojure team)15:05:54

lean on the open invocation

David Orme15:05:54

Following up on Alex's comment, an adage that has served me well: "Only invent something new if you have to."

Franklin18:05:27

I wonder if it's possible to use https://github.com/juxt/pack.alpha#docker-image to build a docker image for a project that uses lein for dependency management and for building uberjars. I've looked at the readme and I'm not sure if I should add pack.alpha to my dependencies? I'm not cont certain how to use it

lukasz19:05:16

Not sure if you need an extra tool for that - a dockerfile for getting dependencies, building an uberjar and creating final image just with the Java runtime and your application is not that complicated (based on my experience)

👍 3
Drew Verlee20:05:16

@USWTQB9RU is what your doing open source? If i could glance at it, i might be able to offer some advice having used pack.alpha before. Keep in mind that Lein can make use of a deps.edn file. I haven't done this before. https://github.com/RickMoynihan/lein-tools-deps But as I believe Lukasz is saying, you might not really need lein.

lukasz20:05:37

Oh, I meant the opposite - you just need Lein, everything else happens in Docker, example based on our internal Dockerfiles: https://gist.github.com/lukaszkorecki/ca2786d0da26e653a9c80e54752f78dc (There's more to it than that, but this should work out of the box )

Drew Verlee00:05:54

Huh I thought juxt lib required deps.edn

viesti13:05:46

pack.alpha is for deps.edn projects only so with Leiningen, Lukasz's example would be enough

👍 3
viesti05:05:15

The https://github.com/GoogleContainerTools/jib library that the docker support of pack.alpha uses is quite interesting, in that it doesn't require docker daemon for building the image and successive builds, and also pushes to a remote registry are quite fast because dependencies are cached into separate layer. That said, with deps.edn, the same could be done by arranging copying of dependencies separately, say in a RUN command (so you get a layer out of this), and also packing source/AOT resources separately. Just that docker daemon is needed for that, but you probably have other uses for running commands at build time also 🙂 The are things like kaniko for building image without docker daemon too. But for the simple case, Lukasz's example very much enough :)