next up previous contents index
Next: Math Operations Up: Introductory Scheme Previous: Numerical Predicates

Control

 

  The fundamental selection function in Scheme is cond . The format of cond is as follows:

 
		 (cond (predicate1 consequent1)

(predicate2 consequent2)

...

(predicateN consequentN))

The cond function evaluates the predicates of its arguments from left to right, and when predicateI evaluates to true, it evaluates consequentI and offers its return value as the return value of the cond. An error occurs if no predicate evaluates to true; often, predicateN is else , a predicate variable that always has value true, such that consequentN is evaluated if none of the others are true.

The if  construct is a special case of cond, where there are only two possibly paths of execution. The format of the if is as follows:

 
		 (if predicate then-part else-part)

In the if construct, predicate is tested; if it returns true, then then-part is evaluated and its value returned as the value of the if; otherwise, else-part is evaluated and its value is returned as the value of the if.



Steven J. Zeil
Tue Mar 4 14:36:27 EST 1997