How do you find out whether one number is unequal to another?
Scheme doesn't provide a built-in procedure to test whether two numbers are unequal, but it's easy to define one:
(You may prefer to use the variable(define (~= first-number second-number) (not (= first-number second-number)))
!= to name this procedure,
if you're acquainted with C; Pascal programmers may prefer
<>, TeX users \not=, and so on.) Why does Scheme provide the other five numerical relations and not this one?
Because the other five are transitive and therefore have a natural
extension to more than two operands, and the multi-operand extensions are
not easily interdefinable. For example, you couldn't simply define
>= as the negation of <, because both
(>= 1 4 2) and (< 1 4 2) are false.
Inequality, on the other hand, is intransitive. It does not have a unique
natural extension to more than two operands (Should (~= 4 7
4) be true or false? Does ``unequal'' mean ``not all equal'' or
``pairwise distinct''?). And its two-operand case is easily definable, as
shown above.
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/unequal.html