问题描述
由于Common Lisp的函数参数按从左到右的顺序求值,所以为什么不使用普通函数:
(defun progn2(& rest body)
(first(last body)))
还有 PROGN
的另一个功能使用函数无法获得的代码:
想象一下此代码位于Common Lisp代码文件中:
(progn
(defmacro foo()))
vs。
(我的progn
(defmacro foo()))
使用 PROGN
编译器将处理 DEFMACRO
表单作为顶级表单。例如,这意味着编译器注意到有一个宏定义,并使其在编译时环境中可用。
使用函数 MY-PROGN
,编译器将无法识别 DEFMACRO
形式,因为它不是顶级形式。 / p>
Since Common Lisp's function arguments evaluate in left-to-right order, why wouldn't use an ordinary function:
(defun progn2 (&rest body)
(first (last body)))
instead of special form?
There is also another feature of PROGN
which you can't get with a function:
Imagine this code in a file of Common Lisp code:
(progn
(defmacro foo () ))
vs.
(my-progn
(defmacro foo () ))
With using PROGN
the compiler will treat the DEFMACRO
form as a top-level form. That means for example that the compiler notes that there is a macro definition and makes it available in the compile-time environment.
Using a function MY-PROGN
, the compiler won't recognize the DEFMACRO
form, because it is not at top-level.
这篇关于Common Lisp:为什么progn是一种特殊形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!