If 和 cond 作为特殊形式
If and cond as special forms
考虑 SICP 中的这两段:
This construct is called a case analysis, and there is a special form
in Lisp for notating such a case analysis. It is called cond (which
stands for “conditional”), and it is used as follows:
...
This uses the special form if, a restricted type of conditional that
can be used when there are precisely two cases in the case analysis.
在此上下文中类型是什么意思(条件的限制类型)?是否表示:
- "if" 是 "cond" 的一种吗?因为句子说的是"there is a special form",所以只有一种特殊形式,因为"if"是"cond"的一种。
- "if" 和 "cond" 都没有关系。它们都是有条件的。如果这是正确的,为什么这句话说 "there is a special form" 就像它只是一个?
在" if
中[是]一种受限类型的条件句,我相信"conditional"并不是具体的意思cond
;一般是"conditional statement / expression"。
所以有两个,cond
和 if
。每个都可以根据另一个来定义,因此给定的实现可以选择仅将其中一个作为原语,根据它来定义另一个;或者实现可以选择将它们都作为原始特殊形式。
特殊形式由解释器(编译器)自己专门处理。
也可以使用宏。它们不会被解释器本身处理,而是由它的宏处理机制处理。
所以if
是有条件的; cond
是条件句; cond
可以有任意数量的子句; if
必须恰好有两个(或 一个或两个 ,具体取决于标准)子句;其余的只是英语。 :)
考虑 SICP 中的这两段:
This construct is called a case analysis, and there is a special form in Lisp for notating such a case analysis. It is called cond (which stands for “conditional”), and it is used as follows:
...
This uses the special form if, a restricted type of conditional that can be used when there are precisely two cases in the case analysis.
在此上下文中类型是什么意思(条件的限制类型)?是否表示:
- "if" 是 "cond" 的一种吗?因为句子说的是"there is a special form",所以只有一种特殊形式,因为"if"是"cond"的一种。
- "if" 和 "cond" 都没有关系。它们都是有条件的。如果这是正确的,为什么这句话说 "there is a special form" 就像它只是一个?
在" if
中[是]一种受限类型的条件句,我相信"conditional"并不是具体的意思cond
;一般是"conditional statement / expression"。
所以有两个,cond
和 if
。每个都可以根据另一个来定义,因此给定的实现可以选择仅将其中一个作为原语,根据它来定义另一个;或者实现可以选择将它们都作为原始特殊形式。
特殊形式由解释器(编译器)自己专门处理。
也可以使用宏。它们不会被解释器本身处理,而是由它的宏处理机制处理。
所以if
是有条件的; cond
是条件句; cond
可以有任意数量的子句; if
必须恰好有两个(或 一个或两个 ,具体取决于标准)子句;其余的只是英语。 :)