Additions to C - range checking

Dick Dunn rcd at nbires.UUCP
Sat Jul 5 16:34:46 AEST 1986


> 	>if (5<a<50) do_something(a);
> 	>
> 	>Is this impossible to parse?
> 	
> 	This was in BCPL, and was a GOOD IDEA.
> 
> COBOL has this too. It is not impossible to parse, but it is not trivial
> either. It requires lookahead to resolve the meaning. Perhaps another syntax?

This suggestion ( 5<a<50 ) seems to come up every few months.  Every few
months someone gets to point out that it exists in Icon and it works.  The
parsing (for Icon, not COBOL) is no different than for any other dyadic
operator; it requires no extra lookahead or magic.  The Icon trick is that
success/failure indications (which drive control structures like "if") are
separate from values.  The operator "<" may either fail (meaning that the
relation does not hold) or succeed.  If it succeeds, it produces its right
operand as result.  The only remaining piece of the puzzle is that "<" is
left-associative (as dyadic operators usually are), so that 5<a<50 means
(5<a)<50.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Simpler is better.



More information about the Comp.lang.c mailing list