顺序结构主要用在需要顺序form组的地方, 有些结构已经隐含有了form组链结的功能:
As a result, `progn' is not used as much as it was many years ago. It is needed now most often inside an `unwind-protect', `and', `or', or in the THEN-part of an `if'.
顺序结构有以下几类:
一般形式:
顺序执行所包含的form,返回最后一个form的返回值:
(progn (print "The first form") (print "The second form") (print "The third form"))
输出的结果为:
-| "The first form" -| "The second form" -| "The third form" => "The third form"
变体1:
(prog1 (print "The first form") (print "The second form") (print "The third form"))
返回第一个form的返回值:
-| "The first form" -| "The second form" -| "The third form" => "The first form"
变体2:
(prog2 (print "The first form") (print "The second form") (print "The third form"))
返回第二个form的返回值:
-| "The first form" -| "The second form" -| "The third form" => "The second form"