Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-adm!brl-smoke!smoke!rbj@icst-cmr From: rbj@icst-cmr (Root Boy Jim) Newsgroups: net.lang.c Subject: Re: Boolean Operators Slighted in C Message-ID: <822@brl-smoke.ARPA> Date: Tue, 13-May-86 21:08:22 EDT Article-I.D.: brl-smok.822 Posted: Tue May 13 21:08:22 1986 Date-Received: Sun, 25-May-86 06:39:30 EDT Sender: news@brl-smoke.ARPA Lines: 79 Doug Gwyn responds: Steven Brian McKechnie Sargent says ("> ..."): > A Boolean data type distinct from integers clutters the language with > another (moderately useless) type and removes handy idioms like > foo[x == 0] = bar; Boolean quantities form an important abstract data type distinct from counters, sets, real numbers, etc. By not making the distinction, the language encourages usage errors, the most notorious being if ( a = b ) stuff; True. It is easily found tho. Sure, one can make integers do double (or triple, or ...) duty, but by now every programmer should realize the value of data abstraction. Or lack of it. I find that the Boolean/Integer schism in Fortran caused me lots of headaches long ago. > New operators like "< =", in addition to being hard to spell and > understand, > facilitate usages that just aren't that common. I hardly ever want to > say x = (x < y), and I don't mind typing the extra characters. I'm not > interested in paying compiler vendors money for supporting this > (or any other dubious misfeature pounded into the language for > "completeness'sake.") Here is an example where proper use of Boolean data would be violated. A statement like x = x < y; should NEVER be used, since it assigns a Boolean result to an arithmetic variable. This means that a "< =" operator is not a good idea. Wrong you are, Doug. You have been thinking in this Boolean paradigm for so long that you are missing another Good thing. Implication! Given that P and Q are `Boolean' variables (0 or 1), the Logical Implication is described by the operator `<='. Thus, the statement `x = p <= q;' sets the `boolean' value x to a `boolean' expression. Since there are no such things as booleans :-), x, p, & q are integers. It's all a matter of interpretation. APL has no `boolean exclusive or' operator because the operator `!=' does the same thing (when given only zero's or one's). There are sixteen different boolean functions with two inputs and one output. They all fit nicely into C operators: p 0 0 1 1 q 0 1 0 1 Name Symbol --------- ---- ------ 0 0 0 0 False 0 0 0 0 1 And & 0 0 1 0 Doesn't Imply > 0 0 1 1 Alpha p 0 1 0 0 Not Implied By < 0 1 0 1 Omega q 0 1 1 0 Diff != or ^ 0 1 1 1 Or | 1 0 0 0 Nor !(p | q) 1 0 0 1 Same == 1 0 1 0 Not Omega !q 1 0 1 1 Is Implied By >= 1 1 0 0 Not Alpha !p 1 1 0 1 Implies <= 1 1 1 0 Nand !(p & q) 1 1 1 1 True 1 Neat! I never thought I'd get to use my engineering switching theory again! I find data abstraction to be a Good Thing, and have produced much better code since defining a Boolean data type and using it in a strictly type-correct manner. This fact doesn't bother people who write in APL, widely considered to be the most mathematical language. Why does it bother you? (Root Boy) Jim Cottrell "One man gathers what another man spills"