Hacker News new | ask | show | jobs
by fsantanna 3432 days ago
Hi, I'm the author of the programming language Céu.

Although Céu is about 5 years now, this is the first time I post to "Show HN".

In this new version, we are trying to surpass the academic fences with a more polished work (docs, build, etc).

All feedback is welcome.

Francisco

5 comments

It would be helpful if you could provide a high-level explanation of what "Structured Reactive Programming" means and what problem you are trying to solve with current solutions? How is it different from current reactive environments?
Thank you, I will improve the page.

In summary:

Reactive: code executes in reactions to events

Synchronous: reactions run to completion, i.e., there's no implicit preemption or real parallelism (this avoids explicit synchronization: locks, queues, etc)

Structured: programs use structured control mechanisms, such as "await" (to suspend a line of execution), and "par" (to combine multiple awaiting lines of execution)

Structured programming avoids deep nesting of callbacks letting you write programs in direct/sequential style. In addition, when a line of execution is aborted, all allocated resources are safely released.

In comparison to FRP/dataflow, it is more imperative supporting sequences/loops/conditionals/parallels. The notion of (multiple) program counter is explicit. Also, everything is lexically scoped, there's no GC involved.

In comparison to promises/futures, it provides lexical parallel constructs, allowing the branches to share local variables and, more importantly, supporting safe abortion of code (with the "par/or").

Synchronous: reactions run to completion, i.e., there's no implicit preemption or real parallelism

Does this mean a program will hang if e.g. disk or network access takes too long?

Yes in theory. But in practice the language includes "async" support so you can guard these few operations that may take long. Like in a functional language you assume everything is pure unless marked to have side-effects, here you assume every reaction is instant unless is something that has to be explicitly "awaited" for. It's a pretty clean model.
Another way of thinking about this (also mentioned in the docs somewhere) is that Ceu "pretends" that any reactive code finishes infinitely fast, similar to how garbage collected languages "pretend" that computers have infinite memory.

Neither truly does, of course, but the idea is that for the vast majority of situations where either type of language is used, that's a good enough approximation, letting you vastly simplify the problem that you're solving.

External calls in C require an underscore (e.g., "_printf") to be easily trackable as possibly unsafe.

Also, at some point in the code (e.g., after you include your libraries), one can disable these calls with a directive.

But typically, one will use bindings for asynchronous libraries, such as libuv (https://github.com/fsantanna/ceu-libuv).

Thank you! I'm enthusiastic with the Arduino binding, it provides a friendly way to handle events without much bloat. These characteristics fit well in this domain of non specialists programming constrained embedded systems.
Perhaps it's a good use-case to highlight on the main page of Ceu?
Why did you choose Lua as the implementation language?
- Dynamic typing for fast prototyping. The compiler is full of dynamic tricks for testing, stripping parts of it, etc.

- LPeg support [1]. PEGs are great!

- The creator of Lua was my advisor since undergrad. :) (Which means that I program in Lua for a long time...)

http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html

And this means that the performance is not the first (or second) reason to use Ceu, right? In other words, is it somewhat slow?
I wrote in Lua the source-to-source compiler that takes a ".ceu" and generates a ".c" (the code is a single-threaded state machine), which is then compiled with gcc.

The compiler is slow, but not the final binary.

We wrote a paper [1] that compares flash,RAM,CPU usage from Céu vs hand-written event-driven code in C. The differences are negligible.

[1] http://www.ceu-lang.org/chico/ceu_sensys13_pre.pdf

Why not plug into LLVM? Just generate an LLVM backend.
- Céu can embed blocks in C and call it directly

- C is more portable

- C is easier to generate

Thanks for posting it. And for sticking with it that long. It is something I will one time do but I did not try enough languages yet to forge my own.
What were your influences ? other "synchronous" languages like lucid ?
The main influence is Esterel, but we visited most synchronous literature (including Lucid).

We also take the syntax from Pascal/Lua and the basic types and expressions from C (due to source compatibility).

Thanks a lot. We had a class in esterel in college, but it flew over my head at the time, sadly. Time to revisit the whole thing.

May I ask you if you have some favorite references/papers about the subject ?

The early papers about Esterel and the synchronous model, e.g.:

- Gérard Berry: "Real time programming: Special purpose or general purpose languages"

For the semantics, I like this paper focusing on abortion (for me, the most expressive construct of synchronous languages):

- Gérard Berry: "Preemption in Concurrent Systems"

There's also a well-known survey:

- Albert Benveniste: "The synchronous languages 12 years later"

This one is about bridging the gap between synchronous and asynchronous, something like Esterel+CSP:

- Gérard Berry: "Communicating reactive processes"

For a modern take (besides Céu), check ReactiveML:

- Louis Mandel: "ReactiveML: a reactive extension to ML"

You can also search for papers from professors Stephen A. Edwards and Reinhard von Hanxleden which still work actively on the subject.

For those who are interested in synchronous reactive programming and speak French, Gérard Berry gave lectures about it (and time-related topics in general) at Collège de France, along with other teachers including M. Pouzet. Videos are publicly available, check out:

http://www.college-de-france.fr/site/gerard-berry/course-201...

http://www.college-de-france.fr/site/gerard-berry/course-201...

(In 2014 - 2016 he moved on to program proofs, which may also interest some of you.)

Cool, I missed those.
Amazing, I'm off to read.

ps: fun, Louis Mandel co-author (M.Pouzet) was a compiler teacher at my college.