6

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#.

Luke Martin
  • 109
  • 7
  • 1
    Regular Clojure already *is* cross platform and allows use of native libraries. Can you be a bit more specific about what you are trying to achieve? If it is just cross-platform native graphics libs you are after, you might look at LibGDX which runs fine from Clojure. – mikera May 01 '13 at 04:53

2 Answers2

2

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!

Maurice Reeves
  • 1,572
  • 13
  • 19
  • Sorry, I meant to quote what you said, but it posted the comment instead. Thanks for this explanation (I'd vote up, but I don't have the rep)! Can you use custom DLLs with your Xamarin:Android/iOS projects? – Luke Martin Apr 30 '13 at 04:17
  • I can't be 100% sure, but I imagine you can, as long as they're compiled, and can load under Mono. The only other thing I'd caution is that Clojure CLR does use the Dynamic Language Runtime, and if you're deploying this onto a mobile platform, that may not work as expected. Can't hurt to try. – Maurice Reeves Apr 30 '13 at 12:57
0

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!

knocte
  • 16,941
  • 11
  • 79
  • 125