The Grinnell Scheme Web: The = procedure

How do you find out whether two numbers are equal?

Call the = procedure, giving it the two numbers as operands:

> (= 5 5.0)
#t
> (= 4 5)
#f
> (= 12 (+ 7 5))
#t
The = 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:
> (= #t #t)

ERROR: =: Wrong type in arg1 #t
``Arity 2 or more''? So you can give the procedure more than two operands? What does it do with the extras?

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:

> (= 5 (+ 2 3) 5.0 (quotient 67 13) (gcd 50 135))
#t
> (= 7 7 7 6.9999 7)
#f
And if you give it one operand, or none?

Some implementations go beyond what the standard requires and generously return the ``true'' Boolean value in these cases:

> (= 5)
#t
> (=)
#t
Under other implementations, however, the program will crash:
> (= 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


created July 1, 1995
last revised December 27, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)