The D Programming Language (was: Still more new operators)

Bob Rose rrr at naucse.UUCP
Mon Feb 8 10:17:40 AEST 1988


In article <11702 at brl-adm.ARPA>, dsill at NSWC-OAS.arpa (Dave Sill) writes:
> >Some years ago I invented the hypothetical notation "e1 ,, e2", which would be
> >like the comma operator in that it evaluates its left operand before its
> >right operand, but (unlike comma) the result would be the value of the left
> >operand.  Look what this buys us:
> >	a,, a=b		/* displacement operator, like a :=:= b */
> >	a=(b,, b=a)	/* a simple swap */
> >	x,, ++x		/* same as x++; but generalizable */
> >	free(stack,, stack=stack->next)	/* pop stack */
> >	stack->value,, pop(stack)	/* pop and return stacked value */
> 
> I like it.  Nice and general, fills a gap missing in C.  It's not C,
> but it could be D (it *should* be D, not P (pee?)).

But wait, we can do better. Why limit yourself to two operands? Let's
look at some other programming language (like Icon) and get the
correct operator.

The magic operator is

              i(x1, x2, x3, ..., xn)

Looks like a function call eh? It's not. i is an integer in the
range from 1 to n and the operator produces the outcome of xi.

So a simple swap is

              a = 1(b, b=a);           /* much cleaner than ,, */

The the wonderful thing is it wont break any code. So everyone
write your ANSI rep now!!!! 8^)

BTW my vote for min and max is ?< and ?>. Also why not ?: that
produces it first operand if it is not zero else it produces it second
that why the getc macro becomes

#define getc(file) (*(file)++->char ?: _fillbuf(file))
    /* note _fillbuf is smart enough to figure out if there was
       a '\0' in the input stream or if it was actually at the
       end of a buffer and of course the buffer size is BUFFSIZE + 1 */

just thinking aload
                                -bob
-- 
Robert R. Rose
Northern Arizona University, Box 20023
Flagstaff, AZ 86011
                    .....!ihnp4!arizona!naucse!rrr



More information about the Comp.lang.c mailing list