Common Lisp: Why progn is a special form?

前端 未结 2 1039
失恋的感觉
失恋的感觉 2021-01-04 01:01

Since Common Lisp\'s function arguments evaluate in left-to-right order, why wouldn\'t use an ordinary function:

(defun progn2 (&rest body)
  (first (las         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-04 01:36

    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.

提交回复
热议问题