Dotcl:.NET 上的 Common Lisp 实现
Dotcl: Common Lisp Implementation on .NET

原始链接: https://github.com/dotcl/dotcl

## dotcl: .NET 上的 Common Lisp dotcl 是一个基于 .NET 运行时的 Common Lisp 实现,可在 Windows、macOS 和 Linux (x86-64 & ARM64) 上实现跨平台执行,无需特定平台的移植。它将 Lisp 代码编译为 CIL (通用中间语言),并且在很大程度上符合 ANSI Common Lisp 标准。 主要特性包括 **在 .NET 应用程序 (C#, F#, VB.NET) 中无缝嵌入 Lisp** 以及使用 `dotnet:` 包 **用 Lisp 编写 .NET 代码**,以便直接访问 .NET 类型和类。 dotcl 利用 NuGet 生态系统,并与许多 Quicklisp 库兼容。它通过使用 Roswell/SBCL 的交叉编译过程进行引导,但随后可以 **自托管** 以进行后续构建。 演示项目展示了 Lisp 与 .NET MAUI、ASP.NET Core、MonoGame 的集成,甚至通过模型上下文协议公开 Lisp REPL。该项目是开源的 (MIT 许可证),并提供关于架构、设计决策和平台特定考虑因素的详细文档。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Dotcl: .NET 上的 Common Lisp 实现 (github.com/dotcl) 26 分,由 reikonomusha 2 小时前发布 | 隐藏 | 过去 | 收藏 | 1 条评论 帮助 Rochus 25 分钟前 [–] 这太棒了。实现这个花了你多长时间,达到如此高的 Ansi 测试兼容性水平?你是否能够重用来自 ABCL 的概念?回复 考虑申请 YC 2026 年夏季项目!申请截止至 5 月 4 日 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Common Lisp implementation on .NET. Lisp source is compiled to CIL (Common Intermediate Language) and runs on the .NET JIT — so the same Lisp image runs on Windows, macOS, and Linux across x86-64 and ARM64 without per-platform porting work.

Broadly conforms to the ANSI Common Lisp standard — verified against the ansi-test suite.

  • Embedding Common Lisp in .NET applications. dotcl.runtime is a regular .NET library; you load it from any C# / F# / VB.NET project, evaluate Lisp code, and call back and forth.
  • Writing .NET code in Lisp. The dotnet: package gives direct access to .NET types: (dotnet:new "System.Text.StringBuilder"), (dotnet:invoke sb "Append" "x"), (dotnet:static "System.Math" "Sin" 1.0). You can subclass .NET types from Lisp via dotnet:define-class — the compiler emits real .NET classes, so frameworks like MAUI, ASP.NET Core, and MonoGame just see them as ordinary subclasses.
  • Cross-platform CL with NuGet ecosystem access. Any NuGet package is reachable from Lisp; any Quicklisp library that doesn't rely on SBCL-only internals tends to work too (asdf, alexandria, etc. are routinely loaded).
# One-time bootstrap: cross-compile dotcl's compiler with Roswell/SBCL.
make cross-compile

# Install as a `dotnet tool`-style global command.
make install

# REPL
dotcl repl

# Evaluate a form
dotcl --eval "(format t \"hello, ~a~%\" (lisp-implementation-type))"

# Run a file
dotcl --load my-program.lisp

After the first cross-compile, dotcl can self-host: DOTCL_LISP=dotcl make cross-compile rebuilds the compiler using dotcl itself.

  • .NET SDK 10+ — see install table below
  • Roswell (only for the initial cross-compile bootstrap — once dotcl is built it can rebuild itself)

Working integrations in samples/:

  • MauiLispDemo — a .NET MAUI app (Windows + Android) where Application / ContentPage / view model are all defined in Lisp via dotnet:define-class.
  • AspNetLispDemo — ASP.NET Core controller written in Lisp, with attribute routing.
  • MonoGameLispDemoGame subclass in Lisp; the Draw override runs on the MonoGame frame loop and animates the background colour.
  • McpServerDemo — Model Context Protocol server exposing a Lisp REPL to MCP clients (Claude Desktop, etc.).

Each sample's README.md walks through the boot pattern.

  • Compiler (compiler/, written in Lisp): transforms S-expressions into a flat list of CIL instructions (SIL).
  • Runtime (runtime/, written in C#): object representation, reader, CIL assembler (PersistedAssemblyBuilder-based for .fasl output and Reflection.Emit for in-memory codegen), and the standard library functions that aren't expressible in pure Lisp.
  • Bootstrap is by cross-compile: a Roswell SBCL runs compiler/cil-compile.lisp to emit compiler/cil-out.sil, which the .NET runtime loads to bring up the Lisp environment. From that point dotcl can rebuild itself.

Architectural detail and design history are in DESIGN.md. Per-change rationale is recorded under docs/decisions/.

  • Windows: see docs/windows.md for installation, encoding (UTF-8 stdin/stdout always), pathname conventions, and Windows-side .NET interop (Registry / WMI / WinForms / MAUI / COM).

MIT. See LICENSE.

联系我们 contact @ memedata.com