9

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.

2
  • Could you give an example of what s-expressions you want the code to be in? vatine gave an example, but you said that it wasn't quite what you wanted. If the format doesn't matter, then could you explain why you want to write it as s-expressions?
    – Chip Uni
    Jan 14, 2010 at 23:29
  • <everything2.com/title/….> Jan 14, 2010 at 23:52

5 Answers 5

7

Related:

2
2

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

2

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.

1
  • 1
    Sort of like that. Although I don't think the s-expression version would look quite like some of the things you did there. Jan 14, 2010 at 16:27
1

Have a look at Tasuku Hiraishi's SC. His International Lisp Conference papers from 2005 and 2007 are archived at archive.org.

See his source repo, in particular the examples.

To my knowledge that is the best of the many attempts to bring S-Expression style coding practices to bear on an otherwise vanilla C project.

0

I know this is an old post, but for the record, I think this is what is being asked for.

The "lispc" project translates c programs written in an s-expressions style to C. It works great and even compiles the code for you if you set it up right.

I don't know that it produces the most readable C code output at the moment though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.