Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

COND

Name: Anonymous 2012-09-05 10:08

Why doesn't C have the sugar syntax for COND yet?

Name: Anonymous 2012-09-05 10:43

Because it has macros.

Name: Anonymous 2012-09-05 10:47

It doesn't need it. case statements are C's equivalent for executing code, and nested x ? y : z works well for inline values.

Name: Anonymous 2012-09-05 12:02

>>3
case statements are in no manner equivalent to cond, neither are ?: statements due to their rules.

The only thing that can do the same as cond would be a chain of if/elses

Name: Anonymous 2012-09-05 13:09

Op hasn't discovered c++ template metaprogramming. It is more powerful than lisp macros (gay)

Name: Anonymous 2012-09-05 13:59

>>5
LOL

Name: Anonymous 2012-09-05 14:33

>>4
I meant something like this:

(define (foo x)
  (cond ((= x 10) 5)
        ((= x 20) 6)
        (#t 0)))


Becoming this in C:

int foo(int x) {
    switch (x) {
        case 10: return 5;
        case 20: return 6;
        default: return 0;
    }
}


That doesn't work for conditions like (> x 0), but it fits some uses of cond well. When wouldn't ?: statements work?

Name: Anonymous 2012-09-05 15:21

Just use if/else chains you retarded LISPweenie

Name: Anonymous 2012-09-05 15:48

That's some dirty code, but it fucking works!

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);

Name: Anonymous 2012-09-05 15:53

>>9
Now let it take lambda functions as arguments to be performed when one of the conditions is found to be true

Name: Anonymous 2012-09-05 16:00

>>10
IHBT

Name: Anonymous 2012-09-05 16:34

print((x < 10 | -1 |: x = 10 | TRUE |: x > 10 | +1.0 | "unordered"))
Algol 68 has a true multi-branch conditional. Branches that yield different types yield a union of those types.
(  IF    CASE
|: THEF  INSE       # removed in the Revised Report #
|  THEN  IN
|: ELIF  OUSE
|  ELSE  OUT
)  FI    ESAC

Name: Anonymous 2012-09-05 18:02

C needs a progn

Don't change these.
Name: Email:
Entire Thread Thread List