val x = 2
val y = square(x)
The right-hand side of a val definition is evaluated at the point of
the definition itself.def loop: Boolean = loop
A definition
def x = loop
is OK, but a definition
val x = loop
will lead to an infinite loop.
true false // Constants
!b // Negation
b && b // Conjunction
b || b // Disjunction
and of the usual comparison operations:
e <= e, e >= e, e < e, e > e, e == e, e != e
Here are reduction rules for Boolean expressions (e is an arbitrary
expression):
!true --> false
!false --> true
true && e --> e
false && e --> false
true || e --> true
false || e --> e
Note that && and || do not always need their right operand to be
evaluated.def abs(x: Int) = if (x >= 0) x else -x
x >= 0 is a predicate, of type Boolean.if (true) e1 else e2 --> e1
if (false) e1 else e2 --> e2
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать