views:

648

answers:

3

I want to write C in s-expressions and use compile-time macros. Does anybody know of anything that does this? It should translate the s-expressions into standard C.

+1  A: 

How do you mean? Something along the lines of:

(c-expression 
  (int main ((int argc) ((array (pointer char)) argv)
    (block
      (printf "%d arguments\n" argc)
      (if (argc >= 1)
        (printf "The first arg is %s\n" (ref argv 1)))
      (return 0))))
=>
"int main (int argc, char *argv[])
{
  printf("%d arguments\n", argc);
  if (argc >= 1)
    printf(The first arg is %s\n", argv[1]);
  return 0;
}

If so, yes, it's definitely doable. However, it's not entirely trivial.

Vatine
Sort of like that. Although I don't think the s-expression version would look quite like some of the things you did there.
Ollie Saunders
+1  A: 

Perhaps you want something like ECL, which compiles Common Lisp to C.

Svante