sidney@saturn.ucsc.edu (Sidney Markowitz ) (08/07/89)
Common LISP also has an n-ary < operator. Since everything is in prefix notation in parentheses, it makes it pretty simple to express: a < b is (< a b) a < b < c is (< a b c) And it generalizes for any number of operands. It should be a simple matter of incorporating this kind of generalized relational operator in some future version of C, simply by switching from infix to reverse Polish notation. (That's a :-), no flames, please!) -- sidney markowitz <internet: sidney@saturn.ucsc.edu or sidney@ai.mit.edu>
fin@uf.msc.umn.edu (Craig Finseth) (08/07/89)
As previous posters have mentioned, the C language already accepts the
syntax:
a < b < c
as valid, with (possibly) surprizing semantics. It is diffcult to
imagine (i.e., I cannot) an upwardly-compatible extension to C that
"corrects" the semantics.
However, do not despair. You can achieve a similar goal merely be
writing a function such as:
int
between(const int a, const int b, const int c)
{
return((a < b) && (b < c));
}
which returns 1 if b is between a and c. While not as elegant as a
built-in solution, it has the advantages of working on just about all
C compilers (you can write it with the old-style parameter
declarations) and use it now.
(For the record, I added "between" (a < b < c), "outside" (c > b > a),
and "within" (a <= b <= c) operators to a little-used data collection
language that I developed.)
Craig A. Finseth fin@msc.umn.edu [CAF13]
Minnesota Supercomputer Center, Inc. (612) 624-3375
willa@hpvcfs1.HP.COM (Will Allen ) (08/09/89)
How about a macro? . . .Will