Live data from Hacker News

ClojureC, a compiler for Clojure that targets C as a backend

github.com

41–50 of 89 posts

Re: ClojureC, a compiler for Clojure that targets C as a backend

#41

So if I wanted to write CLI applications in Clojure, is this my best bet? Cause the JVM is about the least suitable platform I have ever worked with for CLI apps...which is most of what I do. I'm constantly in this pickle of wanting to use Clojure but defaulting to Ruby because the JVM is so terrible at it.

Depending on what you're doing, you can consider the REPL as your CLI and run everything in that process.

Re: ClojureC, a compiler for Clojure that targets C as a backend

#42
post #5

Why C but not llvm? Structured code generation is always better than string-based one.

Similarly, structured control flow (C's if, for, while, switch etc.) is better than unstructured (LLVM IR just has the equivalent of gotos (yes, LLVM IR has switch too, but it can go anywhere, so it still isn't inherently structured)). So it goes both ways.

Some other advantages of C over LLVM IR:

ABI compatibility with C automatically. In LLVM IR, being ABI-compatible with C is often a considerable headache and you have to do different things on each platform.

You can use C libraries by #including their header files (the way many C libraries were designed to be used), instead of hardwiring all that information (macro expansions, enum values, typedefs, inline functions, struct definitions, etc.) from their header files in your code generator.

You have the option of switching C compilers; you're not as locked into a single backend.

With a bit of care, you can make your output much more readable. LLVM IR demands either SSA form (most front-ends don't want to do this) or herds of allocas, loads, and stores everywhere. In C, you just say "int x;" to declare an int, and just "x" to refer to it.

You can use C features like bitfields, designated initializers, short-circuit operators (&&, ||), compound assignment (+=, -=, etc.), and so on. You can do all these things in LLVM IR, but you have to lower them yourself.

Re: ClojureC, a compiler for Clojure that targets C as a backend

#43
post #32
post #29

Earlier quoted context omitted.

More moving parts being more error prone is not generally a controversial opinion.

This argument can just as easily be used to support a claim that generating C via string manipulation can very well be less error prone than relying on a huge, complex API like LLVM. It is not a given that there are "more moving parts" in generating C output from a compiler than in using LLVM.

It is not a given that there are "more moving parts" in generating C output from a compiler than in using LLVM.

While that's a true enough statement by itself, your snipe conveniently skips half of the process in question.

Re: ClojureC, a compiler for Clojure that targets C as a backend

#45

As someone who doesn't use Clojure, but watches it fairly closely, I'd say the least appealing part of Clojure is its reliance on the JVM. As such, I'd say efforts such as these are greatly welcomed.

That's how I felt about it before I started using it. If it's more than just startup time holding you back, I'd give it a shot.

Re: ClojureC, a compiler for Clojure that targets C as a backend

#46
post #40

So if I wanted to write CLI applications in Clojure, is this my best bet? Cause the JVM is about the least suitable platform I have ever worked with for CLI apps...which is most of what I do. I'm constantly in this pickle of wanting to use Clojure but defaulting to Ruby because the JVM is so terrible at it.

If the startup slowness is your problem, look into Nailgun: http://www.martiansoftware.com/nailgun/ If that's not your problem with the JVM, what is?

Nailgun is an additional dependency. And pretty insecure at that.

Re: ClojureC, a compiler for Clojure that targets C as a backend

#47

So if I wanted to write CLI applications in Clojure, is this my best bet? Cause the JVM is about the least suitable platform I have ever worked with for CLI apps...which is most of what I do. I'm constantly in this pickle of wanting to use Clojure but defaulting to Ruby because the JVM is so terrible at it.

You could also use node.js with Clojurescript, if you're willing to accept the compromises of Clojurescript.

I'm not familiar with the compromises of clojurescript nor running node.js as a CLI platform. Got any links that can help explain? Can it be compiled to a static executable?

Re: ClojureC, a compiler for Clojure that targets C as a backend

#49

So if I wanted to write CLI applications in Clojure, is this my best bet? Cause the JVM is about the least suitable platform I have ever worked with for CLI apps...which is most of what I do. I'm constantly in this pickle of wanting to use Clojure but defaulting to Ruby because the JVM is so terrible at it.

The readme for ClojureC says it's still experimental at this point. I'm not sure how far along it is. You might poke around its tests to see what it does so far.

Re: ClojureC, a compiler for Clojure that targets C as a backend

#50
post #40

So if I wanted to write CLI applications in Clojure, is this my best bet? Cause the JVM is about the least suitable platform I have ever worked with for CLI apps...which is most of what I do. I'm constantly in this pickle of wanting to use Clojure but defaulting to Ruby because the JVM is so terrible at it.

If the startup slowness is your problem, look into Nailgun: http://www.martiansoftware.com/nailgun/ If that's not your problem with the JVM, what is?

Nailgun is not a good solution to the problem. If the JVM startup speed is a problem, your best option is to use something not on the JVM and not use hacks that make it feel faster.
Post reply on HN