Fundamentals of CS I (CS151 2001S) : Reference

or - combine (Boolean) results

Basic Version: Booleans

Procedureor
Parametersb1 ... bn, n Boolean values
PurposeDetermines if any of the values is true.
ProducesA truth value: true (#t) if any value is true; false (#f) if all are false.
PreconditionsAll the parameters are Boolean values (unverified).
Examples
> (or #t #t #t)
#t
> (or #f #f #f)
#f
> (or (< 1 2) (< 2 3))
#t
> (or (odd? 1) (odd? 3) (odd? 5) (odd? 6))
#t
> (or)
#f
> (or (even? 1) (even? 3) (even? 4) (even? 5))
#t

Advanced Version: Control

Procedureor
Parametersexp1 ... expn, n expressions
PurposeEvaluates expressions one-by-one until it reaches the end or something that is not false.
ProducesThe value of one of the expressions. Returns false (#f) if all of the expressions evaluate to false. Returns the value of the first non-false expression if any expression is not false.
Preconditions(None)
PostconditionsEvalutes each of the expressions up to (and including) the first one that fails to returns false. If all of the expressions return false, evaluates all of the expressions.
Examples
> (or "hello" "goodbye")
"hello"
> (or (< 3 2) (< 1 0) 'failed)
failed

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

This page was generated by Siteweaver on Thu Feb 22 05:48:13 2001.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/or.html.
You may validate this page's HTML.
The source was last modified Wed Jan 31 22:33:04 2001.