Skip to content

Using ClojureCLR in a C# project

Matthew Tuel edited this page Nov 16, 2024 · 6 revisions

To use ClojureCLR in a C# project, include the ClojureCLR library package via NuGet. The repo is at http://www.nuget.org/packages/Clojure/. From the NuGet console:

Install-Package Clojure

or use your favorite method for including the reference.

The package includes Clojure.dll and supporting files for all supported frameworks. Technically, .Net Standard 2.0 and 2.1 are targeted, so the package will work with projects targeting those and also .Net Framework 4.6.1 (and later), .Net Core 3.1, and .Net 5.0.

In general, one should not call any methods from the clojure.lang._X_ classes directly, even those in clojure.lang.RT, which provides runtime support for the Clojure core functions. For example, RT.load supports clojure-core/load, but the Clojure load function does input massaging and other work around the call to RT.load.

Instead, use the methods in the clojure.clr.api.Clojure class. This class parallels the clojure.java.api.Clojure class in Clojure(JVM). More information is to be found at https://clojure.org/reference/java_interop#_calling_clojure_from_java.

For example:

IFn load= clojure.clr.api.Clojure.var("clojure.core", "load");
load.invoke("some.thing");
Clone this wiki locally