[comp.lang.c] What I'd really like to see in an i

mcdonald@uxe.cso.uiuc.edu (08/07/89)

It would seem that the expression a < b < c is legal C, and might
be a useful construct (especially in the Obfuscated C Contest...).
In fact, it is actually mentioned as legal in K&R I, on page 189.
Of course, they say it "does not mean what it seems to". It also
says relational operators group left-to-right, so it is

(a < b ) < c  .

This tests for c less than 1 or 0 depending on whether  a < b or not.


Doug McDonald

mccaugh@s.cs.uiuc.edu (08/10/89)

 First, I concur with Dworkin that a multiple relation might as well be
 considered (e.g. a <= b < c <= d < e).
 Second, I disagree with the assertion this has nothing to do with 'if',
 since it is usually the purpose of a comparison -- be it simple or compound --
 to execute some statement(s) conditioned upon such a test (which may be why
 the semantics of conventional languages posit a Boolean for the first argument
 to an 'if').
 The problem I have with "liberalizing" such semantics is that the comparison
 operators might not then be able to enter into general Boolean expressions. I
 disagree with the claim about Icon that "tests returning a result or not" is a
 good idea; for one thing, what am I to do in a complex Boolean expression with
 a non-result? I much prefer Backus's suggestion of a 3-values logic (where 
 'bottom' would convey no result): otherwise, there seems to emerge confusion
 between "no result" and "failure". This is more discriminating than to say:
 x/0 => no result (as otherwise, 1=0 <=> 1/0 holds).

 Finally, it would seem that a macro pre-processor for C ought to resolve
 this problem (in a way commensurate with BCPL and COBOL, e.g.).