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

Karl Heuer karl at haddock.ISC.COM
Wed Feb 10 03:37:56 AEST 1988


In article <558 at naucse.UUCP> rrr at naucse.UUCP (Bob Rose ) writes:
>But wait, we can do better [than the proposed ",,"].  Why limit yourself to
>two operands?
>              i(x1, x2, x3, ..., xn)
>[where 1 <= i <= n; the result is xi]

If `i' is constant, this is no more powerful than `(x1, ..., xi,, ...,, xn)'
which produces the same result.  If `i' is allowed to be an arbitrary integral
expression (which I presume is the case in interpretive Icon), then it is
indeed more powerful but also more expensive to compute.  Part of the beauty
of `,,' is that it has a cost comparable to `,'.

>[How about an operator] that produces it first operand if it is not zero else
>it produces it second

I considered proposing that the `||' operator be so extended (yes, this could
break existing code, but only if the operands are nonboolean AND the result is
being used in a nonboolean context).  After thinking about it, though, I
decided that this is a step backwards.  In programs that properly distinguish
between booleans and integers, there's nothing particularly magic about
`compare against zero'.  Why should there be a special-purpose notation for
`e1 != 0 ? e1 : e2' but not for `e1 != -1 ? e1 : e2', say?

What you really want is the `it' pronoun, often used in PDL.
  IF long-hairy-expression != 0
    RETURN it
  ELSE
    RETURN other-expression
  ENDIF

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
KWZH: We need a construct like `e1 UNLESS IT==0 INWHICHCASE e2'.
GCJ:  Yes, and also `IFONTHEOTHERHAND ... WEMAYSAFELYASSUME'.



More information about the Comp.lang.c mailing list