Fork me on GitHub
#clojure
<
2022-06-12
>
javahippie10:06:19

I am trying to make a CLJ library also usable for CLJS projects for the first time. Does anybody know about a blog, documentation or best practices? It is Leiningen based, and after some reading I’m under the impression that switching to deps would make the whole procedure easier… :thinking_face:

p-himik11:06:32

Not much to say here - in the end, it's just a JAR somewhere. But: • Common code should be in .cljc with platform-specific stuff in reader conditionals • It's simpler and easier to store all macros in .clj files • deps.edn will also allow your library to be used as a Git dep Given that your library also works with CLJ, you probably don't care about NPM dependencies, so that's not an issue.

javahippie11:06:12

Forgot to add that information: I have the need to add npm dependencies. My API is a wrapper around a Java library, and the same wrapper should now delegate the call to a very similar npm library. Already moved the code to .cljc files and don’t have any macros

p-himik11:06:58

In this case, specify your dependencies in a deps.cljs file at the root of your projects. Alternatively, just document them in the README. There's been a discussion about it in #clojurescript with some links and advice, should be easy to find via the Search panel.

👍 1
javahippie11:06:33

Will read into that, thanks!

thheller17:06:05

IMHO leiningen is definitely easier

thheller17:06:19

except for adding a deps.cljs file to declare the npm-deps everything else stays the same

thheller17:06:54

no compilation or anything needs to be done

thheller17:06:02

just .cljc files

p-himik17:06:20

Easier - you mean, in terms of packaging a JAR? Or is there something CLJS-specific?

thheller19:06:00

easier as in you just need to run lein deploy clojars

thheller19:06:18

not CLJS specific no since nothing special needs to be done for CLJS

👍 2
kwladyka21:06:51

How AI looks in Clojure? Do we have good libraries? Or in Java? Like for example tensorflow ? In other words I am thinking if it makes sense to do AI in Clojure vs Python.

jcf21:06:10

Worth checking out #uncomplicate, libpython-clj and the http://tech.ml ecosystem.

👍 1
jcf21:06:55

Lots of great stuff here too: https://github.com/scicloj

👍 1
kwladyka21:06:20

thank you for the links. Although I think it moves mi closer to think “doing this in clj is not worth it”

didibus23:06:23

There's definitely people doing AI and ML in Clojure, what are your criteria for "worth it" ?

didibus23:06:39

If your question is "can you", the answer is yes you can. If the question is: "Are there more libraries, frameworks, books and tutorials than for Python", the answer is no, Python has the richest ML ecosystem of all languages. That said, you can use Python libraries from Clojure using libpython-clj, bit you won't find the level of tooling and tutorials/books that you'd have in pure Python.

didibus23:06:46

This website has kinks to all the tooling/libs that exist: https://scicloj.github.io/ for various categories for ML/AI in Clojure

kwladyka06:06:29

> There’s definitely people doing AI and ML in Clojure, what are your criteria for “worth it” ? simplicity. If I can do this in Clojure it doesn’t mean it is good idea. Amount of energy and complexity doing this in Clojure vs Python even when I don’t know Python.

kwladyka06:06:29

If the solution is to use Clojure libpython-clj to use Python, then it sounds using Python directly is simpler.

kwladyka06:06:39

even considering I have to learn Python first

kwladyka06:06:53

unless I don’t have to use Python to do AI and still will be on the same level of simplicity as if I would use Python

kwladyka06:06:58

I have 0 experience with AI

didibus06:06:43

Hum... this is hard to answer. If you have zero experience, Python will have a million times more tutorial, books and videos, etc. So its probably best to use Python. But, there's this which is a big investment, but you learn a lot: https://aiprobook.com/numerical-linear-algebra-for-programmers/ and https://aiprobook.com/deep-learning-for-programmers/ That said, you might be best starting with Python to learn, because of how much material it has. Then revisit Clojure afterwards.

👍 1
kwladyka07:06:35

Thank you for your input

kwladyka07:06:41

To summarise this do I correctly understand in your opinion doing Python in Clojure make sense? Why? Or do you mean not use Python at all in Clojure for AI make sense?

kwladyka07:06:33

let me ask in that way: what is the use case / benefits to use Clojure over Python for AI?

kwladyka07:06:53

I think the “use case” is the point here. Why would choose Clojure over Python for AI?

didibus07:06:19

My summary is, you'll find it easier to learn AI using Python even if you don't know Python but know Clojure. But if you know and like Clojure, doing AI in it is more fun and brings more joy, using the REPL is still really nice, even though notebooks aren't too far from it, and all the Lisp, FP, and everything else you might still miss from Clojure. The only reason to choose Clojure over Python would be because you prefer using Clojure over Python. You could make a case that productionizing some models is easier in Clojure, especially if your services are already in JVM world or Clojure and not in Python. Like taking a trained model / feature computation from Python and putting it in production can be trickier if your prod services are not Python, sometimes you have to rewrite the same thing in your own language, though nowadays you can often put that in a separate microservice running Python in a container.

didibus07:06:26

Clojure is kind of great for data manipulation and processing, which is a big part of AI, but it lacks the amount of tooling/libs specific to AI that Python has and all the documentation about them. That's kind of a pro/cons, like Clojure is a good choice to build AI libs/tooling on, but it doesn't yet have a solid universal toolkit for it that's widely used.

pm4r15:06:51

Other, not mentioned, option is https://github.com/deepjavalibrary/djl and/or clojure wrapper for it: https://github.com/scicloj/clj-djl

kwladyka09:06:39

Can you link me the simple example of using AI Python (for example PyTorch or TensorFlow) in Clojure?