Additions to C - range checking

mcdaniel at uicsrd.CSRD.UIUC.EDU mcdaniel at uicsrd.CSRD.UIUC.EDU
Mon Jul 7 11:01:00 AEST 1986


/* Written  7:42 pm  Jun 30, 1986 by franka at mmintl.UUCP in uicsrd:net.lang.c */
>In article <523 at ccird1.UUCP> rb at ccird1.UUCP (Rex Ballard) writes:
>>Is this impossible to parse?

>To my knowledge (I don't know
>everything), only COBOL actually does this.

As a comparative language note, ICON does it.  "a < b"  returns "b" if
the comparison succeeds; with left-to-right association of "a < b < c",
it works.

The tricky part is that I haven't said what happens if the comparison
is false.  In that case, the expression "fails", and the rest of the
statement is skipped; the next statement is executed.  (Actually, ICON
has PROLOG-like goal-directed evaluation:
	2 < find("a", "ababc")
will fail; find will be "resumed" where it left off to find any later
substrings and the expression will return 3.  It would take kilobytes
to explain fully.)  So this model is not applicable to C, alas.

To find the max of two variables in C, we can say
	if (a < b) a = b;
In ICON, the idiom is
	a <:= b
Almost any binary operator can augment assignment, like C's "+=".
This is "a := a < b"; if a >= b, the comparison fails and the rest of
the statement is skipped.

I think ICON is a truly great, clean language (for its domain).

> I, for one, think it's a good
> idea; but for new languages, please -- don't try and change C to accomodate
> it.
Yeah.



More information about the Comp.lang.c mailing list