In interactive theorem provers (ITPs), extensible syntax is not only crucial to lower the cognitive burden of manipulating complex mathematical objects, but plays a critical role in developing reusable abstractions in libraries. Most ITPs support such extensions in the form of restrictive "syntax sugar" substitutions and other ad hoc mechanisms, which are too rudimentary to support many desirable abstractions. As a result, libraries are littered with unnecessary redundancy. Tactic languages in these systems are plagued by a seemingly unrelated issue: accidental name capture, which often produces unexpected and counterintuitive behavior. We take ideas from the Scheme family of programming languages and solve these two problems simultaneously by proposing a novel hygienic macro system custom-built for ITPs. We further describe how our approach can be extended to cover type-directed macro expansion resulting in a single, uniform system offering multiple abstraction levels that range from supporting simplest syntax sugars to elaboration of formerly baked-in syntax. We have implemented our new macro system and integrated it into the new version of the Lean theorem prover, Lean 4. Despite its expressivity, the macro system is simple enough that it can easily be integrated into other systems.
翻译:在互动的理论验证器(ITPs)中,扩展的语法不仅对于降低操纵复杂数学对象的认知负担至关重要,而且对于在图书馆开发可再使用的抽象功能也具有关键作用。大多数ITPs都支持这种扩展,其形式是限制性的“合成糖”替代系统和其他特别机制,这些替代机制太简陋,无法支持许多可取的抽象功能。结果,图书馆被无谓的冗余所淹没。这些系统中的战术语言受到一个似乎无关的问题的困扰:意外取名,这往往会产生出乎意料和反直觉的行为。我们从规划方案语言的组合中获取想法,同时解决这两个问题,提出一个新的卫生宏观系统,为 ITPs定制。我们进一步说明我们的方法如何能够扩大,以涵盖类型导向的宏观扩展,从而形成一个单一的统一系统,提供从支持最简单的合成糖到制定以前烤制的合成语法等多个抽象层次。我们实施了新的宏观系统,并将其融入新版本的Laan theorem practificer, Lean 4.尽管其明确性,但宏观系统非常简单。