cjanet

38 points by veqq


This is like Fennel, but for C - letting you write C code in lisp, here are some examples (which double as documentation).

andreyorst

I've made a similar, albeight a much simpler attempt at generating C from fennel, using a simple s-expr transpiler, directly used inside fennel code as a macro, that utilizes Luajit's cffi. Didn't go much further than a prototype, so I'm excited to see how things done here, and maybe update my implementation.

bitshift

This is like Fennel, but for C - letting you write C code in lisp

What sorts of use cases is this meant for? I think I understand Fennel's use case: you have some host software that already takes Lua scripts as input, and Fennel gives you some of the benefits of Lisp without having to modify the host—just compile your scripts to Lua and plug them in like normal.

But with C, you're already recompiling/relinking the host program, so the same benefit (not having to modify the other software) doesn't seem to be there?

I think I'm missing something. Janet already has a C API, so it's not that. Maybe it's an easier version of the C API in some way? Maybe you get compiler optimizations if you write your inner loop in cjanet? Maybe you want to programmatically generate C code without having to suffer C macros?

(Regardless of the use case, this seems like a cool project!)

christine

Janet provides a limited kind of intensional function analysis in the form of disasm, which returns the IR for a given function. By writing something like an abstract interpreter for the disassembly, you could recompile Janet functions into C (or any other language, for that matter) without need for a deeply embedded DSL. I've tried building a POC for this before, but didn't end up making much progress with it.