# Class 11: Conditionals Lab

Back to Conditionals. On to Conditionals (3).

Held: Monday, 15 September 2003

Summary: Today we continue our study of conditionals by working with them experimentally.

Related Pages:

Assignments

Notes:

Overview:

• Basic comparisons.
• Predicates.
• Boolean functions.
• The `cond` operations.
• Lab: Conditionals.

## Comparators

• We've noted that `if` has the form
```(if test truepart falsepart)
```
• What kinds of values can be used for the test?
• The comparison of two numeric values, e.g., <, >, <=.
• Comparisons for equality, e.q., `equals?`, `eq?`
• Lots of other stuff, too.

## Type Predicates

• One common test takes the form Is this datum a value of this type?
• For example, you can test whether a value is a `number?`, `list?`, `rational?`, and much much more.

## Boolean Operators

• Scheme provides a few basic operations for combining Boolean values.
• `(not exp)`
• Has the value true when exp has the value false.
• Has the value false otherwise.
• `(and exp1 exp2)`
• Has the value false when either exp1 or exp2 has the value false.
• Has a not-false value otherwise.
• `(or exp1 exp2)`
• Has the value false when both exp1 and exp2 have the value false.
• Has a not-false value otherwise.
• You'll get to explore the details in more depth in the lab.

## The `cond` Statement

• When you find that you're nesting a whole lot of `if` statements, you're much better off using the `cond` statement, which has the form
```(cond (
(test1 exp1)
(test2 exp2)
(test3 exp3)
...
(testn expn)
(else default)))
```
• The meaning is, in essence, Evaluate each test in turn. When one holds true, use the value of the corresponding expression and stop. If none holds, use `default`.

## History

Thursday, 28 August 2003 [Samuel A. Rebelsky]

• Created automatically.

Back to Conditionals. On to Conditionals (3).

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 9 13:59:36 2003.
The source to the document was last modified on Mon Sep 1 13:30:51 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003F/Outlines/outline.11.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu