previous
|
index
|
next
Conditional Evaluation
Suppose: if your income is less than $10,000 you pay no income tax. Otherwise, you pay 20%.
Scheme's
if
expression:
(if
test-expr
then-expr
else-expr
)
test-expr
must evaluate to true or false
then-expr
is evaluated if
test-expr
is true
else-expr
is evaluated if
test-expr
is false
Procedures that return true or false are
predicates
. Examples:
<, >, =, >=, <=, zero?, even?, equal?
Example:
(if (= 2 3) -10 37.5)
evalutes to 37.5
then-expr
and
else-expr
can be any expressions
previous
|
index
|
next