How do you find out whether one number is greater than another?
Call the > procedure:
The> (> 5 12) #f > (> 12 5) #t > (< 12 12) #f > (< 12 12.0) #f > (< 12.0 12) #f
> procedure is of arity 2 or more, and all of its
operands must be integer, rational, or real numbers. Not complex numbers?
That's right. Complex numbers aren't arranged as less and greater, so
> can't be used to compare them.
What does the > procedure do with more than two
operands?
If you give the > procedure more than two operands, it tests
whether all of the operands are in strictly descending numerical
order (``monotonically decreasing,'' in mathematical jargon). If any of
the operands is less than or equal to any of those that follow it, the
procedure returns the ``false'' Boolean value:
And if you give it one operand, or none?> (< 6 5 4 3 2 1) #t > (< 1 2 3 4 5 6) #f > (< 5 4 3 3.0 2 1) #f > (< 5 4 3 4 2 1) #f
Some implementations go beyond what the standard requires and generously return the ``true'' Boolean value in these cases:
Under other implementations, however, the program will crash:> (> 5) #t > (>) #t
> (> 5)
Error: wrong number of arguments
(> 5)
The prudent programmer will avoid calling the > procedure
with fewer than two operands.
Next topic
Previous topic
Table of contents
This document is available on the World Wide Web as
http://www.math.grin.edu/~stone/scheme-web/greater.html