一句话:通过为视频编辑构建分层 DSL,展示 Racket 教条如何自然导向语言层级并复用宿主语言与类型检查 DSL。
视频会议录制的视频编辑流程高度重复,传统上依赖非线性 GUI 编辑器逐个人工编辑,效率低下。本文遵循 Racket 教条,为视频编辑构建分层 DSL:面向用户的函数式声明式 DSL 负责声明阶段,内部 DSL 封装底层 C 库完成命令式渲染,另用支持类型形式编程的 DSL 注入类型检查。该案例表明,视频编辑可自然分为声明式阶段与命令式渲染阶段,因此创建函数式声明式语言能显著减少手工劳动。最终,这一用户 DSL、内部 DSL 与类型检查 DSL 的层级结构,清晰展示了 Racket 教条如何导向语言层级,并与传统函数式语言中的模块层级相类比。
The Racket doctrine tells developers to narrow the gap between the terminology of a problem domain and general programming constructs by creating languages instead of just plain programs. This pearl illustrates this point with the creation of a relatively simple domain-specific language for editing videos. To produce the video proceedings of a conference, for example, video professionals traditionally use "non-linear" GUI editors to manually edit each talk, despite the repetitive nature of the process. As it turns out, video editing naturally splits the work into a declarative phase and an imperative rendering phase at the end. Hence it is natural to create a functional-declarative language for the first phase, which reduces a lot of manual labor. This user-facing DSL utilizes a second, internal DSL to implement the second phase, which is an interface to a general, low-level C library. Finally, we inject type checking into our language via another DSL that supports programming in the language of type formalisms. In short, the development of the video editing language cleanly demonstrates how the Racket doctrine naturally leads to the creation of language hierarchies, analogous to the hierarchies of modules found in conventional functional languages.
@article{AndersenCF17,
title = {Super 8 languages for making movies (functional pearl)},
author = {Leif Andersen and Stephen Chang and Matthias Felleisen},
journal = {Proceedings of the ACM on Programming Languages},
volume = {1},
number = {ICFP},
year = {2017},
doi = {10.1145/3110274}
}