Now that we have an evaluator expressed as a Lisp program, we can experiment
with alternative choices in language design simply by modifying the evaluator.
Indeed, new languages are often invented by first writing an evaluator that
embeds the new language within an existing high-level language. For example,
if we wish to discuss some aspect of a proposed modification to Lisp with
another member of the Lisp community, we can supply an evaluator that embodies
the change. The recipient can then experiment with the new evaluator and send
back comments as further modifications. Not only does the high-level
implementation base make it easier to test and debug the evaluator; in
addition, the embedding enables the designer to snarf
features from the underlying language, just as our embedded Lisp evaluator uses
primitives and control structure from the underlying Lisp. Only later (if
ever) need the designer go to the trouble of building a complete implementation
in a low-level language or in hardware. In this section and the next we
explore some variations on Scheme that provide significant additional
expressive power.
既然我们已经将求值器表述为一个 Lisp 程序,就可以通过修改求值器来实验各种不同的语言设计选择。事实上,新语言往往正是通过先编写一个将新语言嵌入某种现有高级语言的求值器来发明的。例如,若想与 Lisp 社区的其他成员讨论对 Lisp 的某种拟议修改,我们可以提供一个体现了该修改的求值器。对方就可以用这个新求值器做实验,并将意见以进一步修改的形式反馈回来。高级语言的实现基础不仅使测试和调试求值器变得更容易,而且这种嵌入方式还让设计者能够直接借用底层语言的特性——正如我们嵌入式 Lisp 求值器直接使用底层 Lisp 的基本过程和控制结构。只有在之后(如果有必要的话),设计者才需要费力用低级语言或硬件来构建完整的实现。在本节和下一节,我们将探讨 Scheme 的若干变体,它们提供了重要的附加表达能力。