Common Lisp: Why progn is a special form?

前端 未结 2 1003
失恋的感觉
失恋的感觉 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:43

    progn returns all the values of the last form it evaluates, your function returns just the first one:

    (progn (values 1 2 3)) 
    =>  1, 2, 3
    (progn2 (values 1 2 3)) 
    =>  1
    

    Another critical feature of progn (mentioned by Rainer first) is that it keeps all its forms top-level, which makes it possible for macros to expand to multiple forms (see, e.g., my answer to "“value returned is unused” warning when byte-compiling a macro").

提交回复
热议问题