Name: Anonymous 2012-09-05 10:08
Why doesn't C have the sugar syntax for COND yet?
case statements are C's equivalent for executing code, and nested x ? y : z works well for inline values.
case statements are in no manner equivalent to cond, neither are ?: statements due to their rules.cond would be a chain of if/elses
(define (foo x)
(cond ((= x 10) 5)
((= x 20) 6)
(#t 0)))int foo(int x) {
switch (x) {
case 10: return 5;
case 20: return 6;
default: return 0;
}
}(> x 0), but it fits some uses of cond well. When wouldn't ?: statements work?
int cond(int count, ...)
{
assert(count > 0);
va_list ap;
va_start(ap, count);
int predicate = 0, result;
while (count-- || !predicate)
{
predicate = va_arg(ap, int);
result = va_arg(ap, int);
}
va_end(ap);
return result;
}
int y = cond(3,
x < 10, 5,
x == 10, 6,
x > 10, 7);
print((x < 10 | -1 |: x = 10 | TRUE |: x > 10 | +1.0 | "unordered"))( IF CASE
|: THEF INSE # removed in the Revised Report #
| THEN IN
|: ELIF OUSE
| ELSE OUT
) FI ESAC
progn