The Grinnell Scheme Web: The even?
procedure

Is the syntax of the even? procedure exactly that that of the odd? procedure?

Yes, they are completely analogous:

> (even? 8)
#t
> (even? -7)
#f
> (even? 0)
#t
> (even? -6.1)

ERROR: even?: Wrong type in arg1 -6.1
The arity of the even? procedure is 1, and the operand must be an integer.

So why does Scheme have both procedures? If you had odd?, couldn't you just define even? as its negation?

Sure. In fact, that's the way it works in Pascal -- the odd-parity test is predefined, and if you want the even-parity test you define it yourself. My guess is that the designers of Scheme felt that taking either predicate as ``more primitive'' than the other was tantamount to dabbling in mystical numerology. Since there's no clear reason for preferring one to the other, they gave us both.

That seems a little strange. Don't you want to start with some kind of minimal set of predefined procedures, to keep the language as simple as possible?

If you did that, you wouldn't predefine either odd? or even?, since you can define both of them in terms of procedures that we've already seen:

(define (even? number)
  (zero? (modulo number 2)))

(define (odd? number)
  (= (modulo number 2) 1))
On the other hand, once the designers decided to add a predefined parity predicate to the language, it would have been a false economy to put one in without the other: Which one is ``primitive'' and which one had to be included from the programmer's library of stock procedures would have been just one more detail for her to remember. It's better this way.


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/even-ques.html


created July 2, 1995
last revised December 29, 1995

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