SICP

Conditional Expressions and Predicates

条件表达式与谓词
The general form of a conditional expression ispredicate_predicate ?
_predicate
? consequent-expression : alternative-expression
谓词 结果表达式替代表达式
Conditional expressions begin with a predicate—that is, an expression whose value is either true or false, two distinguished boolean values in JavaScript. The primitive boolean expressions true and false trivially evaluate to the boolean values true and false, respectively. The predicate is followed by a question mark, the consequent-expression, a colon, and finally the alternative-expression.
条件表达式起始于一个谓词

case analysis -> conditional expression

谓词:一个值是 true 或 false 的表达式
The word _predicate _is used for operators and functions that return true or false, as well as for expressions that evaluate to true or false.

conditional-expression syntactic form is right-associative.
js 的条件表达式是右结合的(也就是类似右侧自动加括号的效果)
express a case analysis with multiple cases by nesting conditional expressions as alternative expressions inside other conditional expressions
image.png
We call a predicate pi together with its consequent expression ei a clause.
A case analysis can be seen as a sequence of clauses, followed by a final alternative expression.
谓词和他的结果表达式叫子句,js 的多条件嵌套表达式,就是多个子句加最右侧,结束替代表达式。

there are logical composition operations, which enable us to construct compound predicates.
有一些逻辑组合操作符,使我们能够构造 复合谓词:

  • expression1 && expression2
    • This operation expresses logical conjunction, meaning roughly the same as and. This syntactic form is syntactic sugar for expression1 ? expression2 : false.
  • expression1 || expression2
    • This operation expresses logical disjunction, meaning roughly the same as or. This syntactic form is syntactic sugar for expression1 ? true : expression2.
  • ! expression
    • This operation expresses logical negation, meaning roughly the same as not. The value of the expression is true when expression evaluates to false, and false otherwise.

Notice that && and || are syntactic forms, not operators;
与 和 或是一种语法形式,不是操作符;
Syntactic forms that are simply convenient alternative surface structures for things that can be written in more uniform ways are sometimes called syntactic sugar, to use a phrase coined by Peter Landin.
语法形式最终也会被转化为操作数表达式(操作数与操作符),它只是一种通用的更语义化(be written in more uniform ways)或是大家都认可的一种统一形式,也就是更能让人理解看懂,所以也会被称为语法糖

The operator ! , It is a unary _operator.
! 则是一个一元运算操作符
The operator ! precedes its argument; we call it a_prefix operator
.
放置在参数前的操作符,叫前置操作符
Unary operators have higher precedence than binary operators
一元操作符优先级总是高于二元操作符
A unary operation is an operation with only one operand.