Skip to content

Instantly share code, notes, and snippets.

@jamesdavidson
Created December 19, 2023 04:02
Show Gist options
  • Save jamesdavidson/0b6cf035df7267efe45690884eed30ae to your computer and use it in GitHub Desktop.
Save jamesdavidson/0b6cf035df7267efe45690884eed30ae to your computer and use it in GitHub Desktop.
nREPL with clojure CLR on dotnet 7
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Clojure" Version="1.12.0-alpha8" />
<PackageReference Include="clojure.tools.nrepl" Version="0.1.0-alpha1" />
</ItemGroup>
</Project>
using clojure.lang;
using System.Reflection;
// start up Clojure runtime including compiler
RT.Init();
// make .cljr file resources available from DLL
Assembly.Load("clojure.tools.nrepl");
Assembly.Load("clojure.tools.reader");
// compile nREPL lib
var ns = "clojure.tools.nrepl";
RT.var("clojure.core", "require").invoke(Symbol.intern(ns));
// create nREPL server (default port is 1667)
var startServer = RT.var(ns, "start-server!");
var server = startServer.invoke();
// allow exit on Ctrl-C by shutting down server
var stopServer = RT.var(ns, "stop-server!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment