How do you find out whether two numbers are equal?
Call the = procedure, giving it the two numbers as operands:
The> (= 5 5.0) #t > (= 4 5) #f > (= 12 (+ 7 5)) #t
= procedure is of arity 2 or more, and all of its operands
must be integer, rational, real, or complex numbers. Giving it a
non-numeric operand is an error:
``Arity 2 or more''? So you can give the procedure more than two operands? What does it do with the extras?> (= #t #t) ERROR: =: Wrong type in arg1 #t
If you give the = procedure more than two operands, it tests
whether all of the operands are equal. If it finds any two that
are not, it returns the ``false'' Boolean value:
And if you give it one operand, or none?> (= 5 (+ 2 3) 5.0 (quotient 67 13) (gcd 50 135)) #t > (= 7 7 7 6.9999 7) #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/equal.html