News for hackers. Stuff that matters.
[deleted]
Re:CoffeeScript 1.6.0 released with support for source maps by tikhonj on Monday March 04, 2013 @04:34PM (#5321124)
Yeah, I would also love a "CoffeeScript for C". Honestly, I think C is a rather overrated language--it's liked not because it's good but because it's the best at what it does. And best is only a relative measure!

The most promising thing I've seen is CIL[1][2]. This is not a language per se, but it follows the same idea as CoffeeScript: simplify and get rid of stupid edge cases and odd syntax. The difference is that CIL is designed as an intermediate language (hence the name); it's a target for a DSL, compiler or code generator more than a language proper.

[1]: http://www.cs.berkeley.edu/~necula/cil/index.html [2]: http://kerneis.github.com/cil/

For embedded programming, I think a DSL embedded in Haskell or OCaml outputting C through CIL can give you all the benefits of C without many of the problems. More importantly, it gives you a power to abstract that C sorely lacks, as well as a nice type system.

There are some existing DSLs in this vein (that is, generating C rather than using CIL necessarily). One example I came across recently is atom[3], but I haven't used it (or any other language like that). It's certainly something to keep in mind.

[3]: http://hackage.haskell.org/package/atom/

Of course, all these DSL-based approaches are a larger departure from C than CoffeeScript is from JavaScript, but I think that a good thing.

Re:CoffeeScript 1.6.0 released with support for source maps by chc on Monday March 04, 2013 @06:02PM (#5321622)
Many languages — Haskell included — can compile to C. Compiling down to C and then piggybacking off the system C compiler is a fairly common way of getting a sophisticated native codegen without needing to implement one yourself. But simply compiling down to C doesn't necessarily put the language in the same relationship with C that CoffeeScript is with JavaScript.

To be honest, I could imagine a slightly nicer skin over C, but C is already a pretty good C. Any "CoffeeScript for C" would probably work out to a poor reimplementation of an early C++ compiler with the semicolons removed.

Re:CoffeeScript 1.6.0 released with support for source maps by tikhonj on Monday March 04, 2013 @06:37PM (#5321786)
This isn't compiling Haskell down to C. It's using a DSL to generate C. The DSL just happens to be embedded in Haskell.

Haskell is just an environment, a language factory. Haskell is used for creating the abstractions and meta-programming. You can also piggy back on Haskell's type system to enforce certain invariants.

But ultimately the semantics of the DSL--what actually gets turned into C--are not necessarily related to Haskell at all. Instead, the semantics are tailored for your particular application. In the particular case of atom, this application is hard real-time programming.

Another example is something one of my friends worked on in OCaml. He essentially created a little algebraic system which provided all the operations for a field (with maybe a couple other ones). This is enough to implement a bunch of variations on a Kalman filter. He could then iterate quickly and test the code locally; when he was content, he could use the same code to output abstraction-free C which he could then compile and deploy on ARM.

The point being that the host language is not related to C; it's the embedded DSL that plays the role of CoffeeScript. (Although any reasonable DSL would be quite a larger departure from C than CoffeeScript is from JavaScript.) You just use Haskell/OCaml/Scala/whatever to save having to implement a parser, type system and so on.

Re:CoffeeScript 1.6.0 released with support for source maps by steveklabnik on Tuesday March 05, 2013 @03:13AM (#5323509)
I thought `-f-via-c` was removed long ago.
Re:CoffeeScript 1.6.0 released with support for source maps by chc on Tuesday March 05, 2013 @03:47AM (#5323605)
AFAIK it isn't removed, but it is no longer developed and requires GHC to be in unregistered mode, which most people's won't be. But I could simply be behind the times.
Re:CoffeeScript 1.6.0 released with support for source maps by steveklabnik on Tuesday March 05, 2013 @02:46PM (#5326855)
Looking into it, we're both right, in a way:

  > This is the oldest code generator in GHC and is generally not included any
  > more having been deprecated around GHC 7.0. Select it with the -fvia-C flag. 
So it was deprecated, just never removed.
Re:CoffeeScript 1.6.0 released with support for source maps by ConstantineXVI on Monday March 04, 2013 @03:55PM (#5320856)
In the case of Erlang, Elixr[0] is probably what you're looking for.

[0] http://elixir-lang.org/

Re:CoffeeScript 1.6.0 released with support for source maps by chc on Monday March 04, 2013 @03:58PM (#5320875)
CoffeeScript is deliberately tied to JavaScript by design. Porting it to work with Erlang or C would be rather awkward. Outside the context of a JavaScript environment, CoffeeScript doesn't seem to offer enough benefits over, say, Python to be worth the massive amount of work this would entail. If you mean you want another language that can interact with Erlang or C code, those already exist (in fact, there are a lot of langauges that are C-compatible since it's the lingua franca of modern computing).

And if you want an alternative Erlang, see Elixir (http://elixir-lang.org/), Joxa (http://joxa.org/) and LFE (https://github.com/rvirding/lfe).

Re:CoffeeScript 1.6.0 released with support for source maps by roryokane on Tuesday March 05, 2013 @02:26AM (#5323371)
By “CoffeeScript for C“, I think Onr means not supporting all of CoffeeScript’s features in C, but rather making a language that is very much like C, but better. So CoffeeScript for C wouldn’t try to implement `@foo` to mean `this.foo`, since there is no `this` in C. Rather, it would look at the common idioms in C that are more verbose than they need to be and shorten them.

CoffeeScript for C would probably use semantic whitespace, like normal CoffeeScript. Maybe it would make writing types easier – it would support a syntax for types that doesn’t require the use of http://www.cdecl.org/. It would still try to be “just C”, so it wouldn’t support much higher-level features like function closures.

Re:CoffeeScript 1.6.0 released with support for source maps by tmzt on Wednesday March 06, 2013 @11:00PM (#5335992)
You might consider something like Vala (valac), which produces glib/gobject c code from a c# like syntax.
Re:CoffeeScript 1.6.0 released with support for source maps by roryokane on Tuesday March 05, 2013 @12:56AM (#5323157)
I’m writing a simple “CoffeeScript for C” right now for my CS 283 Systems Programming class’s final project. It’s due in two weeks, but my work so far is on GitHub now: https://github.com/roryokane/cs283-final-project. It won’t do much – it will just compile three kinds of syntactic sugar – but I hope to make it composable enough to extend it in the future.

The three syntactic sugars I’m including are these: allow indents instead of {}; automatically add semicolons; remove parentheses from if/while/for conditionals. I’m trying to make my compiler robust enough to not cause problems like JavaScript’s automatic semicolon insertion does.

This project is just CoffeeScript for C for now, but I’m aiming in the future to make a generic “CoffeeScript for C-like languages”, that can be adapted to work with languages like with ActionScript and Java with only minor tweaking.

Re:CoffeeScript 1.6.0 released with support for source maps by lucian1900 on Monday March 04, 2013 @05:22PM (#5321422)
For C, Rust (and perhaps Go) is not too far off.