请问HN:Lisp的eval和Lisp的宏,它们是相同的基本概念吗?
我的理解是否正确,Lisp 强大的宏系统源于能够用 Lisp 本身编写 eval 函数?根据我的了解,Lisp 从一小组原始操作和特殊形式开始——在最初的 Lisp 中有七个,包括 lambda。我记得保罗·格雷厄姆在他的某篇文章中演示过,仅用这些原始操作就可以构建一个 eval 函数。这些原始操作通常是在像 C 这样的宿主语言中实现的,但一旦你在 Lisp 中有了一个 eval 函数,就可以通过新的规则来扩展它。底层的 C 解释器只看到原始操作,但作为程序员,你可以通过 eval 引入新的语法规则。这似乎是理解宏的一种方式,因为你实际上是在添加新的语言规则。我知道 Lisp 宏通常使用像 defmacro 这样的特定关键字来定义,但核心思想是否相似——通过在 eval 函数上构建新规则来扩展语言?
查看原文
Is my understanding correct that Lisp's powerful macro system stems from the ability to write the eval function in Lisp itself? From what I gather, Lisp starts with a small set of primitives and special forms—seven in the original Lisp, including lambda. I recall Paul Graham demonstrating in one of his essays that you can build an eval function using just these primitives. Those primitives are typically implemented in a host language like C, but once you have an eval function in Lisp, you can extend it with new rules. The underlying C interpreter only sees the primitives, but as a programmer, you can introduce new syntax rules via eval. This seems like a way to understand macros, where you effectively add new language rules. I know Lisp macros are typically defined using specific keywords like defmacro, but is the core idea similar—extending the language by building on the eval function with new rules?