一句话:提出 Racket 的 syntax-spec 元语言,使 DSL 实现兼得自动宏扩展与编译优化,并重新实现 miniKanren。
特定领域语言的实现通常需要在可扩展性与性能优化之间取舍:miniKanren 社区以往也在不同实现中分别探索扩展机制与优化技术。本文介绍 Racket 的新元语言 syntax-spec,它让程序员能直接实现既自动具备宏扩展能力、又能接受常规编译器优化的 DSL。作者用 syntax-spec 重新实现关系式编程 DSL miniKanren,将优化编译器与扩展机制统一在同一实现中,同时保持 Racket 与 miniKanren 之间如同浅嵌入般无缝集成。该工作以函数式珍珠形式展示如何调和 DSL 的可扩展性与编译性能,并体现多语言 DSL 的构造方法。
Implementations of domain-specific languages should offer both extensibility and performance optimizations. With the new syntax-spec metalanguage in Racket, programmers can easily create DSL implementations that are both automatically macro-extensible and subject to conventional compiler optimizations. This pearl illustrates this approach through a new implementation of miniKanren, a widely used relational programming DSL. The miniKanren community has explored, in separate implementations, optimization techniques and a wide range of extensions. We demonstrate how our new miniKanren implementation with syntax-spec reconciles these features in a single implementation that comes with both an optimizing compiler and an extension mechanism. Furthermore, programmers using the new implementation benefit from the same seamless integration between Racket and miniKanren as in existing shallow embeddings.
@article{BallantyneGH24,
title = {Compiled, Extensible, Multi-language DSLs (Functional Pearl)},
author = {Michael Ballantyne and Mitch Gamburg and Jason Hemann},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {ICFP},
year = {2024},
doi = {10.1145/3674627}
}