Last active
November 20, 2016 08:39
-
-
Save zhouqiang-cl/187f0dd8cb2a22e8629ea69cb79b51cd to your computer and use it in GitHub Desktop.
common lisp 的宏 PROG1, PROG2 和特殊操作符 PROGN, MULTIPLE-VALUE-PROG1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
语法 | |
prog1 first-form form* => result-1 | |
prog2 first-form second-form form* => result-2 | |
progn form* => result* | |
multiple-value-prog1 first-form form* => first-form-results | |
参数和值 | |
first-form --- 一个 form (form表示一个会被求值的对象) | |
second-form --- 一个 form | |
forms --- 隐式的 progn | |
result-1 --- first-form 产生的第一个值(primary value) | |
result-2 --- second-form 产生的第一个值(primary value) | |
result --- form的值 | |
first-form-results --- first-form产生的值(所有值) | |
描述 | |
prog1 先对 first-form 求值, 然后对 forms 求值, 返回 first-form 的 primary value | |
prog2 先对 first-form 求值, 然后对 second-form 求值, 然后对 forms 求值, 返回 second-form 的 primary value | |
progn 对form求值,但除了最后一个值外其他的值都被丢弃 | |
multiple-value-prog1 先对 first-form 求值, 然后对 forms 求值, 返回first-form的值 | |
代码片段 | |
* (prog1 (values 1 2 3) 4) | |
1 | |
* (prog1 5 6 7 8) | |
5 | |
* (prog2 (values 1 2 3) 4) | |
4 | |
* (prog2 5 6 7 8) | |
6 | |
* (progn 1 2 3) | |
3 | |
* (progn (values 1 2 3)) | |
1 | |
2 | |
3 | |
* (multiple-value-prog1 (values 1 2 3) 4) | |
1 | |
2 | |
3 | |
TODU | |
为什么 PROG1, PROG2 称之为宏, 而PROGN,MULTIPLE-VALUE-PROG1称之为特殊操作符 | |
PROG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment