[net.lang.c++] Wish List

garry@batcomputer.TN.CORNELL.EDU (Garry Wiegand) (03/21/86)

As long as we're adding amenities to the language, I have a small wish...

All the binary operators in C have a "please modify" form:

	i = i + 3;   -->   i += 3;

Why don't the unary operators have one as well? In particular, I sometimes
write loops in which a logical or bit variable oscillates on and off, using
either foo = ~foo or foo = !foo. Would it be more pleasing to the eye to
have:

	foo = ~foo;   -->   ~~foo; /* Means: please bitwise-complement foo */
	foo = !foo;   -->   !!foo; /* Means: please logically-complement foo */

I suppose foo!! and foo~~ should be provided too, for the sake of symmetry with
++ and --.

Of course, screwily written (macros without proper parenthesizing, for
example) existing programs would break. But fortunately there isn't
much extant C++ yet. Just a thought -

garry wiegand
garry%cadif-oak@cu-arpa.cs.cornell.edu

kwh@bentley.UUCP (KW Heuer) (03/23/86)

In article <429@batcomputer.TN.CORNELL.EDU> garry@batcomputer.TN.CORNELL.EDU
(Garry Wiegand) proposed a new syntax:
>	foo = ~foo;   -->   ~~foo; /* Means: please bitwise-complement foo */
>	foo = !foo;   -->   !!foo; /* Means: please logically-complement foo */
>
>Of course, screwily written (macros without proper parenthesizing, for
>example) existing programs would break.

"~~" would probably be safe since it's a no-op under current semantics;
but "!!" is actually used by some people to convert an int into a canonical
truth-value (i.e. map all non-zero values to 1).  I think this usage might
even be mentioned in K&R?  Anyway, C++ is designed to extend the C language,
as opposed to being a new language, so I suspect this is unacceptable.

Anyway, an equally useful operation is "foo = -foo".  Your notation doesn't
generalize; clearly we can't write "--foo" for this!

I'd like to see an binary operator ",," which is a generalization of the
postfix "++" and "--".  "e1,,e2" should evaluate e1, save the result,
evaluate e2, and return the saved result.  Given this, "x++" is "x,,++x"
and "x--" is "x,,--x".

Is it useful?  Consider the code fragment:
	free(p);
	return (p->value);
which makes the dangerous assumption that p->value is still valid after
free().  This should be written
	temp = p->value;
	free(p);
	return (temp);
but my notation would avoid the extra variable:
	return (p->value,, free(p));

aglew@ccvaxa.UUCP (03/23/86)

>As long as we're adding amenities to the language, I have a small wish...
>
>All the binary operators in C have a "please modify" form:
>
>	i = i + 3;   -->   i += 3;
>

While we're at it, why not make *ALL* the binary operators have a "please
modify" form: && and || do not  (at least not in any compiler I've used).

(This is one of my pet peeves: booleans are not given equality rights 
by languages, nor by architectures)

kdmoen@watcgl.UUCP (Doug Moen) (03/25/86)

>>As long as we're adding amenities to the language, I have a small wish...
>>
>>All the binary operators in C have a "please modify" form:
>>
>>	i = i + 3;   -->   i += 3;

>While we're at it, why not make *ALL* the binary operators have a "please
>modify" form: && and || do not  (at least not in any compiler I've used).


The 'please modify' forms of the unary operators could be written as:
	-= a;	==>	a = -a;
	~= a;	==>	a = ~a;
	!= a;	==>	a = !a;
I think this is upward compatible with existing C programs.


As for making *all* of the binary operators have a 'please modify' form:
I think we run into problems with the relational operators:
	a === b;	==>	a = a == b;	/* no problem */
	a <= b;		==>	a = a < b;	/* this won't work */


And there are definite problems with overloading '.' and '->':
	a.b
could be interpreted either as referencing member 'b' from struct 'a',
or as a function call:
	operator.(a, b)
Both of these interpretations could be valid if both a member 'b' and a
variable 'b' are defined.
-- 
Doug Moen (watmath!watcgl!kdmoen)
University of Waterloo Computer Graphics Lab

bing@galbp.UUCP (Bing Bang) (03/26/86)

In article <> kwh@bentley.UUCP writes:
>In article <429@batcomputer.TN.CORNELL.EDU> garry@batcomputer.TN.CORNELL.EDU
>(Garry Wiegand) proposed a new syntax:
>>	foo = ~foo;   -->   ~~foo; /* Means: please bitwise-complement foo */
>>	foo = !foo;   -->   !!foo; /* Means: please logically-complement foo */
>>
>>Of course, screwily written (macros without proper parenthesizing, for
>>example) existing programs would break.
>
>"~~" would probably be safe since it's a no-op under current semantics;
>but "!!" is actually used by some people to convert an int into a canonical
>truth-value (i.e. map all non-zero values to 1).  I think this usage might
>even be mentioned in K&R?  Anyway, C++ is designed to extend the C language,
>as opposed to being a new language, so I suspect this is unacceptable.

i like the idea, i suggest changing the syntax to post operators:

	foo = ~foo;   -->   foo~~; /* Means: please bitwise-complement foo */
	foo = !foo;   -->   foo!!; /* Means: please logically-complement foo */

this will avoid any clashes with the existing syntax.

bing

-- 
"Break, but never bend."		from an oak tree i know
			...that can move in two directions at the same time

...akgua!galbp!bing

kwh@bentley.UUCP (03/28/86)

In article <307@galbp.UUCP> galbp!bing (Bing Bang) writes:
>i like the idea, i suggest changing the syntax to post operators:
>	foo = ~foo;   -->   foo~~; /* Means: please bitwise-complement foo */
>	foo = !foo;   -->   foo!!; /* Means: please logically-complement foo */
>this will avoid any clashes with the existing syntax.

It still can't be extended to the unary minus ("foo--" is taken), which in
my experience is the most common case anyway.

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint