# 用Lean4验证Clojure核心代码发现17个未报Bug

Original title: I checked Clojure's core with Lean and found unreported bugs

> Hacker News story 50642939 · language: zh · submitted 2026-11-25
> Web version: https://zeli.app/zh/story/50642939
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 164 · by [encyclopedism](<https://news.ycombinator.com/user?id=encyclopedism>) · 💬 57
[original](<https://s.conao3.com/blog/2026/e4f733>) · [HN discussion](<https://news.ycombinator.com/item?id=50642939>)

## Summary

我读了Koukyosyumei用Lean4形式验证Rust开源项目发现大量Bug的文章后，决定对Clojure的核心库进行同样的检查。我利用hirosassa/lean-verify工具，将Clojure核心中用Java编写的部分建模到Lean4中，并通过差分测试对比java.util集合。结果令人意外：在Clojure 1.12.7中发现了17个从未被报告过的Bug。这些问题包括vector-of的reduce操作死循环、HAMT哈希冲突节点在dissoc时隐藏键值、以及removeIf在有无类型提示时行为不一致等。这些Bug隐藏在代码深处，常规测试难以触及，但通过形式化验证和差分测试被成功捕获。这不仅揭示了持久化数据结构的复杂性，也展示了形式化方法在发现隐蔽缺陷方面的巨大价值。

## Key quote

> 我发现了17个在Clojure的JIRA或ask.clojure.org上都找不到报告的Bug。

## HN discussion (57 comments)

### [rvprasad](<https://news.ycombinator.com/item?id=50645750>)

> 虽然这项努力很有趣，但我发现列表中有两个问题。
>
> 首先，(.indexOf (seq (byte-array [1 2 3])) 2) 会失败，因为 byte arrays 存储的是字节，而传给 `.indexOf` 的参数 2 是一个 Long 值。简单的类型检查（哪怕是用肉眼扫一眼）本就能标记出这种错误用法。我认为如果能减少这类噪音，这类练习会更有价值。
>
> 其次，(get "abc" 1.9) 会失败，因为在字符串对象的上下文中，`get` 会将给定的 key 强制转换为整数，这在弱类型语言的语境下是合理的。话虽如此，我认为详细记录 `get` 的行为，对客户端的帮助不亚于直接返回 `nil` 或“未找到”的值。然而，我们仍然面临这样的问题：“由谁、在何处划定语言动态性的界限？”以及“我们依据的约定语义究竟是什么？”

### [yababa_y](<https://news.ycombinator.com/item?id=50647213>)

> 我也在 sbcl、clozure 和 ACL2 中发现了数十个问题：https://github.com/emberian/common-lisp-compiler-audit

### [networked](<https://news.ycombinator.com/item?id=50646090>)

> 所以现在这类工作也用 Lean 来做了吗？基于我在 2010 年代对依赖类型语言世界的粗略了解，我原本以为是用 Rocq（前身为 Coq）来验证程序正确性的。
>
> 语言模型在编写 Lean 方面是否比编写 Rocq 显著更好？

### [vitorsr](<https://news.ycombinator.com/item?id=50645910>)

> 这挺有意思的，毕竟像 Nubank（巴西数字银行）这样的重量级玩家基本上都运行在 Clojure 上，他们收购/并购了 Rich 的 Cognitect。我原本会预期这些基础类型和函数是完美无缺的。

### [siscia](<https://news.ycombinator.com/item?id=50646011>)

> 我真的需要去学学 Lean 以及这些测试机制了。

---

## Cite

- Page: https://zeli.app/zh/story/50642939
- Date: 2026-11-25
- Source: s.conao3.com (https://s.conao3.com/blog/2026/e4f733)
- Hacker News: https://news.ycombinator.com/item?id=50642939

## Other languages

- en: https://zeli.app/story/50642939 · markdown: https://zeli.app/story/50642939.md
- ja: https://zeli.app/ja/story/50642939 · markdown: https://zeli.app/ja/story/50642939.md
- ko: https://zeli.app/ko/story/50642939 · markdown: https://zeli.app/ko/story/50642939.md
- de: https://zeli.app/de/story/50642939 · markdown: https://zeli.app/de/story/50642939.md
- es: https://zeli.app/es/story/50642939 · markdown: https://zeli.app/es/story/50642939.md
- ru: https://zeli.app/ru/story/50642939 · markdown: https://zeli.app/ru/story/50642939.md
