Scheme Programmer's Manual
or - short-circuiting conditional, return the first true value
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(or test ...)
The test expressions are evaluated from left to right
until one returns a true value or the last test is reached.
In the former case, the or expression returns the value without
evaluating the remaining expressions.
In the latter case, the last expression is evaluated and its
values are returned.
If there are no tests, #f is returned.
- Chez Scheme, Loko Scheme
The source-level optimizer can rewrite code that uses multiple values
in one of the test expressions in such a way that the values are no
longer in a single-value context. This can mean that code which would
otherwise raise an exception will run without error, but with possibly
unexpected results. This is not a bug and is permitted by R6RS.
- Vicare Scheme
The test expressions are statically checked to see that they return a
Returns the value of the first true expression. In Scheme everything
is true except for the false value (#f or #false in R7RS).
The last test expression is in tail context if the or expression
(or (= 2 2) (> 2 1)) => #t
(or (= 2 2) (< 2 1)) => #t
(or #f #f #f) => #f
(or '(b c) (/ 3 0)) => (b c)
(or) => #f
The or syntax is very common in almost all programming
languages. It is sometimes called or and other times && or
something else. It is used when several expressions should be tested
but evaluation should not continue past the first true value.
When expressions are more complicated it is better to use
The or syntax is widely compatible across Lisp systems.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
Zero or more than one value was returned by a non-tail test
expression. Implementations may also handle this in another way, as
long as the safety guarantees of R6RS [sc] 5.6 are upheld.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
Short-circuiting evaluation was invented in the 1950s by John
McCarthy, the creator of Lisp.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Return to Main Contents
- IMPLEMENTATION NOTES
- RETURN VALUES
- APPLICATION USAGE
- SEE ALSO