clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-05-10T00:37:31.255500Z

Thanks

Max 2021-05-10T13:54:38.257600Z

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

alexmiller 2021-05-10T13:59:37.258Z

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

dharrigan 2021-05-10T14:18:00.259600Z

@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? <https://groups.google.com/g/clojure/c/Zpc2yaZDxqA>

alexmiller 2021-05-10T14:35:56.260500Z

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)

borkdude 2021-05-10T14:52:08.260700Z

spec does this

Max 2021-05-10T15:08:23.263500Z

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

Max 2021-05-10T15:26:21.264Z

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

vlaaad 2021-05-10T15:27:03.264300Z

(defmulti foo :type)

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

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

vlaaad 2021-05-10T15:27:27.264700Z

@max.r.rothman use interop 🙂

alexmiller 2021-05-10T15:28:07.265Z

I think you're abusing multimethods trying to do this

alexmiller 2021-05-10T15:29:35.265400Z

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

alexmiller 2021-05-10T15:29:54.265700Z

lean on the open invocation

David Orme 2021-05-10T15:45:54.265800Z

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

Franklin 2021-05-10T18:45:27.268600Z

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

viesti 2021-05-11T13:18:46.270100Z

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

👍 1
viesti 2021-05-12T05:59:15.294900Z

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 :)

lukasz 2021-05-10T19:32:16.268800Z

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)

👍 1
2021-05-10T20:36:16.269100Z

@franklineapiyo 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.

lukasz 2021-05-10T20:43:37.269400Z

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 )