From: daveg@synaptics.com (Dave Gillespie)
Newsgroups: comp.lang.c++
Subject: Re: New C++ type: boole
Date: 27 Jul 92 00:00:54 GMT
Organization: Synaptics, Inc., San Jose, CA
In-reply-to: dougm@titan.cs.rice.edu's message of 26 Jul 92 05:42:14 GMT

In article <DOUGM.92Jul25234214@titan.cs.rice.edu> dougm@titan.cs.rice.edu (Doug Moore) writes:
> Dave> If you define "t!!" as a single token, may the fleas of a thousand
> Dave> camels, well, you get the idea.  :-)
> 
> Dave> Let's do away with t!! and f!! altogether:  The expressions !!1 and
> Dave> !!0 are just as simple, and we get them for free.  I find them easier
> Dave> to tell apart at a glance, too.
> 
> Although the needs of the writers of scanners was not my primary
> concern when I proposed t!! and f!!, I can agree that they might make
> their lives a little difficult, and might make everyone's scanners a
> little slower.

I wasn't as concerned with the difficulty of writing the scanner as
much as with the aesthetics of the language.  Making a C++ token which
was a mixture of letters and operator symbols would be confusing and
awkward.  Surely there must be something prettier, something more
consistent with the rest of the language, that we could use.

> On the other hand, I do want boole literals and not circumlocutions
> like !!0 and !!1.  I could live with 0t and 0f, and I don't think the
> scanner writers would wish upon me an infestation of dromedary vermin
> for inventing those two particular symbols.  Would they?

Is "!!0" such a circumlocution?  Consider the constant "-2.3".  We
read and write this as a simple number, but the C++ grammar considers
it a unary "-" operator with the unsigned literal "2.3".  C++ has no
token for -2.3, so it expresses it as a simple, canonical expression
that generates the value.  !!0 and !!1 are just the same, albeit
somewhat less obviously canonical.

Your "0t" and "0f" are not bad, but I don't like "0t"'s implication
that the numeric value of the literal is zero.  "int(0t) == 1" would
be very confusing.  How about "0b" and "1b", analogous to "0L" and
"1L"?  Since "boole" is an integral type, it makes sense for it to
follow the conventions of integer literals, i.e., an integer value
followed by a type suffix letter.

> Dave> What can be done to ease the transition from current C++ to C++
> Dave> with booleans?
> 
> Well, one could probably cook up a class boole that one could
> conditionally include if using an unenlightened compiler.  That
> wouldn't solve everything.  Anytime you add to the language, programs
> that use the new features can't be compiled with the old compilers.  I
> can't see a global solution to that.

I was concerned that programs written during the transition period
would be forced to work under both systems, and that the most
obvious simulations of "boole" on older compilers would not be
satisfactory.  Maybe a true "boole" class would---I just wanted to
point out that this is an area that deserves careful thought.

"Boole" is not simply an addition to the language, since its
presence would change the meanings of existing constructs which
appear in every C++ program.

> Dougm> The behavior of an expression of the form E1 &&= E2 is equivalent to
> Dougm> E1 ? (E1=(E2)) : f!, except that E1 is evaluated only once.
> 
> Dave> Any reason you wrote it that way instead of as "E1 = E1 && E2"?
> 
> I wrote it that way to emphasize that in E1 &&= E2 or E1 ||= E2, no
> assignment need take place if E1 has the appropriate value.  That
> is probably sufficiently obvious to go unsaid.

As far as I know, the compiler can always delete a useless assignment
unless the variable in question is volatile.  For symmetry's sake,
I prefer to think in terms of "E1 = E1 && E2", myself.

								-- Dave
--
Dave Gillespie
  daveg@synaptics.com, uunet!synaptx!daveg
  or: daveg@csvax.cs.caltech.edu