If the test evaluates to true, the second argument will be evaluated. If the test evaluates to false, and a third (or "else") argument is present, it will be evaluated.
The "Cond" function is a bit more complicated. It takes any number of arguments. Each argument should be a list containing two elements. The first element in each list is a test, and the second can be any expression. Cond runs through the pair in order, evaluating each test until it finds one that returns true. At that point "cond" evaluates and returns the expression associated with the winning test.
ox --> (if (> 2 1) 'yes 'no) yes ox --> (if (< 2 1) 'yes 'no) noA "cond" example:
ox --> (define animal 'cow) cow ox --> (cond ((eq? animal 'pig) 'oink) ((eq? animal 'cat) 'meow) ((eq? animal 'cow) 'moo) (else 'huh?)) mooNotice cond can have an "else" test which always will evaluate to true if all of the other tests fail.
Also notice cond can be used to select from a general list of choices. Here we will randomly select a shape:
ox --> (define pick (ceiling (* (rand) 4))) 2 ox --> (cond ((= pick 1) (sphere)) ((= pick 2) (cone)) ((= pick 3) (box)) ((= pick 4) (cylinder))) #fSince pick was assigned 2, a cone would have been created.
mrl