Is it possible to use Clojure CLR with C# in Xamarin?

1.6k Views Asked by At

I love Clojure. It is by far my favorite language.

I've just found Xamarin, which allows you to have cross-platform apps, making full use of native libraries. The language used with it is C#.

Now I'm wondering if there is any way to program the majority of my Xamarin apps in Clojure (CLR), instead of C#.

2

There are 2 best solutions below

2
On

So, Clojure CLR will let you use any libraries it can load. For example, I've loaded the Oracle.DataAccess libraries, and the NLog libraries into Clojure CLR, so it's theoretically possible to load the Xamarin libraries the same way:

;;; not sure which library you want to include, using this as a placeholder
(assembly-load-from "C:/Path/To/Xamarin.Core.dll")

That being said, Xamarin itself appears to also be an IDE, and a set of build tools on top of their own proprietary libraries and build tools, so it may not be possible to fully integrate the two. Also, I think Xamarin works purely with C#, so coding in Clojure is probably not possible...directly.

What you can do is create some libraries in Clojure CLR, and compile them down to DLLs, which you can then link to, so you can build the bulk of your logic in Clojure, and then create some simple C# wrappers that your Xamarin app consume.

I'd love to hear back on what you try, and whether or not you're successful doing this.

Best of luck!

0
On

Possibly yes in Android, but in the case of iOS I would say it's not likely, because the latter is a platform which has a lot of limitations around generated code, reflection, and the like. And Clojure being dynamically typed has high chances of being affected.

Honestly, the Clojure in the .NET world would fit more with F# (also functional, immutable by default, etc), which is a language that has just been adopted as official by Xamarin (meaning you can use it in Android and iOS, and Mac).

It's also statically typed (as opposed to Clojure) so this may mean that it's also faster. Give it a try!