How do you find out whether one number is less than another?
Call the < procedure:
The> (< 5 12) #t > (< 12 5) #f > (< 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 ascending numerical
order (``monotonically increasing,'' in mathematical jargon). If any of
the operands is greater 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?> (< 1 2 3 4 5 6) #t > (< 6 5 4 3 2 1) #f > (< 1 2 3 3.0 4 5) #f > (< 1 2 3 2 4 5) #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/less.html