我没看到你调用 Assembly.Load 的地方,这是必需的。尝试在 Program.cs 中这样做
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!");
Console.CancelKeyPress += (_, _) => stopServer.invoke(server);
下面是一个合适的 example.csproj 文件
<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>
我在 Ubuntu 22.04 上使用 dotnet 7.0.114。在空目录中放入这两个文件后,只需运行
dotnet restore
dotnet run
祝您玩得开心!