TRUE and FALSE
Stephen P Spackman
stephen at estragon.uchicago.edu
Fri Sep 7 14:15:18 AEST 1990
To pick up on a couple of comments:
In article <1990Sep6.113259.2109 at ifi.uio.no> jar at ifi.uio.no (Jo Are Rosland) writes:
Why can't I do this in C? The && and || operators are defined
to return either 0 or 1. With the Lisp semantics I could write
code like:
return f() || g();
instead of:
a = f();
if (a)
return a;
else
return g();
This is useful eg. when f() and g() return pointers (maybe in
some sort of search, where we only want to call the second
function if the first one fails.) And I even think the first
version reads better.
The single most important case is, of course, when f() and g() return
functions. You could code all of that ecchy high-level
strategy-finding code in this style:
return (f() || g())(x);
And if THAT ain't clarity, I don't know what is.
In article <1990Sep6.113259.2109 at ifi.uio.no> jar at ifi.uio.no (Jo Are Rosland) writes:
The is_true() macro is almost as useful as a macro you might
write to return the numeric value of its argument, i.e.:
a = value_of( b ) + value_of( c );
I'm in favour, though I'd like to see a prefix operator for this.
There damn well ought to be an operator for extracting values from
variables, so people don't confuse them with constants.
And to encourage them to USE constants.
(And it's been done in real languages, honest).
stephen p spackman stephen at estragon.uchicago.edu 312.702.3982
More information about the Comp.lang.c
mailing list