Clojure hosted on Python

Are there any official efforts/plans to introduce Clojure on Python in order to have full access to the data science, ML and AI packages? Yes I know there is Basilisp. which is fantastic but I wonder if an official leap into this arena is even remotely realistic.

1 Like

We use libpython-clj for this.

Yep thanks. Great advice. My question was more pointing to the possibility of officialy hosting a new Clojure on the ‘last frontier’ host Python after Java (Clojure) and JS (Clojure Script)

1 Like

I sort of doubt that’d be worth the effort - the more I learn about the JVM, and the more I learn about the python runtime, the less I think something like what you’re describing is a good idea.

[just saw you’re a first-time poster - I’m not actually trying to be that flippant; perhaps other knowledgeable folks here would like to discuss the pros and cons hosting Clojure on Python :smile:]

This has been explored very early in Clojure’s lifetime. Tim Baldridge had an implementation (forked at GitHub - drewr/clojure-py: A implementation of Clojure in pure (dynamic) Python), along with more revisions and explorations but it was eventually publicly abandoned (I think there were some blog posts or mailing lists about the reasoning). I think (based off mailing list posts) he got it up to py 2.7, but abandoned it due to speed issues. Then he went off researching pypy, rpython, and implemented pixie lang (a clojure inspired language written in rpython with a jit) among other research topics.

"At this point I’ve moved on from Clojure-Py. The amount of hoops I needed to jump through to get Clojure semantics on Python ended up having too many drawbacks. "

That doesn’t mean someone else couldn’t reinvigorate the effort, but I just haven’t seen any demand or initiative since like 2015. People seem okay with bridging as a compromise.

1 Like

Have you ever had a look at Basilisp? Chris Rink accomplished a lot of that in a personal project. Especially in data science and AI, all frameworks and packages of any seriouspedigree run on Python, nobody and I mean nobody hosts on JVM.
It would be a great expansion of Clojure to cover that area of application.

Yes I am a first-time poster and new to Clojure but I have decades of experience in computer science and IT consulting having worked with all kinds of languages like C, C++, Scheme, Prolog, Java, JS, Rust etc.

I would be very interested in your expert opinion on Basilisp

2 Likes

I don’t have an opinion on basilisp; I don’t use it but I am aware of it. Just stating the prior art relative to your query, e.g. why there is no formally supported clojure-on-python. Maybe basilisp will be able to overcome the hurdles that clojure-py could not, or maybe it remains as a pragmatic compromise that gets you 95% of clojure on modern python.

I personally think python kind of sucks and Gumped its way into popularity :slight_smile: Such is life.

For what it’s worth, the SciCloj folks are working to build out the data science story in Clojure (consolidating efforts and getting fundamental infrastructure built out, since about 2019), in addition to just bridging into Python, R (and even early julia bindings) out of pragmatism. AI/ML side of the Clojure house is pretty much leveraging aforementioned bindings, or java/scala/native based stuff through the JVM. Much of the discussion happens on the Zulip board if you want to poke around.

2 Likes

Thanks for your input

1 Like

I have used basilisp, in a hobby setting, to write Clojure code to run in Blender:

The work there is great, and the effort that has gone into making that experience smooth is very, very admirable.

nobody and I mean nobody hosts on JVM

Well, we do.

And we like it. Personally, I believe there’s a lot of promise in functional programming for data science and machine learning. Exploring these ideas and solving problems in this area for the last decade has been enlightening, and fun, and lucrative.

1 Like

Thanks for the input. I am happy that you had positive experiences with Baslisp. I only tinkered a little and it made a great impression on me for a personal project.

When I said ‘nobody hosts data science on JVM’ (I apologize for the abrasiveness) I meant all the well known frameworks pytorch, tensorflow, jax, numpy, pandas, scikit-learn etc all live on Python and it would be great if there was a more official support for Clojure on Python - thanks again

2 Likes

I think Basilisp is what you want. It’s pretty feature complete, and well maintained.

libpython-clj is the other way around, let’s you use Python libs from Clojure. But Basilisp is a Clojure implementation that runs over the Python VM.

Thanks. I makes a pretty solid impression

@Dirk_Roeckmann Using Python libraries from Clojure should be possible with GraalPy. From their website:

GraalPy provides a Python 3.11 compliant runtime. A primary goal is to support PyTorch, SciPy, and their constituent libraries, as well as to work with other data science and machine learning libraries from the rich Python ecosystem.

The online book Practical Artificial Intelligence Programming With Clojure shows how to use some Python libraries from Clojure (not through GraalPy).

Also check out ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator. It has a Java API.

While Python is the best known platform for data science and ML, Python as a language and also its runtime are suboptimal for doing this kind of work. For this reason the Elixir community has been developing a complete ecosystem that leverages the same C++ libraries as Python, and can also call Python libraries when needed.

The Clojure community has been on the same track developing a data science stack that leverages existing C++ and Java libraries. There is also similar work in the Scala community.

Building an ecosystem that is on par with the Python ecosystem requires a huge amount of work. Hopefully AI will one day make it possible to rewrite a whole ecosystem in another language. Then everybody will we able to choose the tool they consider the best fit :slight_smile:

Thanks for the info. I will have a look