News for hackers. Stuff that matters.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Monday January 30, 2017 @05:06AM (#13519835)
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

Re:Show HN: Céu, Structured Synchronous Reactive Programming by teleclimber on Tuesday January 31, 2017 @12:25PM (#13532815)
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?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @12:37PM (#13532946)
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").

Re:Show HN: Céu, Structured Synchronous Reactive Programming by jessaustin on Tuesday January 31, 2017 @08:55PM (#13537484)
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?

Re:Show HN: Céu, Structured Synchronous Reactive Programming by hisham_hm on Tuesday January 31, 2017 @09:09PM (#13537553)
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.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by vanderZwan on Wednesday February 01, 2017 @05:59AM (#13539785)
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.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Wednesday February 01, 2017 @03:14AM (#13539207)
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).

Re:Show HN: Céu, Structured Synchronous Reactive Programming by pizza on Monday January 30, 2017 @06:11AM (#13520128)
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Monday January 30, 2017 @06:37AM (#13520273)
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.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by vanderZwan on Monday January 30, 2017 @07:35AM (#13520639)
Perhaps it's a good use-case to highlight on the main page of Ceu?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by zerr on Tuesday January 31, 2017 @02:12PM (#13534114)
Why did you choose Lua as the implementation language?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @02:20PM (#13534224)
- 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

Re:Show HN: Céu, Structured Synchronous Reactive Programming by zerr on Tuesday January 31, 2017 @02:31PM (#13534341)
And this means that the performance is not the first (or second) reason to use Ceu, right? In other words, is it somewhat slow?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @02:37PM (#13534402)
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

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fenollp on Wednesday February 01, 2017 @04:16AM (#13539451)
Why not plug into LLVM? Just generate an LLVM backend.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Wednesday February 01, 2017 @04:35AM (#13539522)
- Céu can embed blocks in C and call it directly

- C is more portable

- C is easier to generate

Re:Show HN: Céu, Structured Synchronous Reactive Programming by tluyben2 on Tuesday January 31, 2017 @08:41PM (#13537388)
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.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by agumonkey on Wednesday February 01, 2017 @02:21AM (#13539001)
What were your influences ? other "synchronous" languages like lucid ?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Wednesday February 01, 2017 @03:04AM (#13539179)
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).

Re:Show HN: Céu, Structured Synchronous Reactive Programming by agumonkey on Wednesday February 01, 2017 @03:10AM (#13539195)
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 ?

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Wednesday February 01, 2017 @03:32AM (#13539285)
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.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by catwell on Wednesday February 01, 2017 @06:27AM (#13539874)
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.)

Re:Show HN: Céu, Structured Synchronous Reactive Programming by agumonkey on Wednesday February 01, 2017 @09:20AM (#13540859)
Cool, I missed those.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by agumonkey on Wednesday February 01, 2017 @03:33AM (#13539291)
Amazing, I'm off to read.

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

Re:Show HN: Céu, Structured Synchronous Reactive Programming by ratstew on Tuesday January 31, 2017 @01:21PM (#13533484)
What are the advantages of Céu over other synchronous programming languages such as Esterel and Lustre?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @01:36PM (#13533672)
In comparison to Esterel:

1. Dynamic abstractions with lexical scope (vs. mostly static language). You can dynamically spawn code into a lexically-scoped pool.

2. Internal/fine-grained determinism (vs. external determinism). All statements execute in a deterministic order. E.g., if you have two printf's in parallel awaking from the same event, they will execute in lexical order.

3. Safe integration with C. When calling a C function that returns a pointer (e.g., "malloc"), Céu forces you to write a finalization clause (in which you can call "free"). If this code is somehow aborted, the "free" is called automatically.

4. Timers as first-class events (e.g., "await 1s"). Besides the convenience, Céu adjusts timers in sequence, e.g., if a first timer awakes a little bit late (due to system overhead), the timer in sequence will compensate.

5. Internal events are stack-based (vs. queue based). This allows co-routine-like functionality, resumable exceptions, and some other mechanisms.

6. Event-based logical notion of time (vs. tick based). A single event can occur at a logical time (related to #2).

[EDIT] Didn't mention that these are "advantages" depending on the context. Esterel targets hardware synthesis and also hard real-time systems. Dynamic abstractions might be irrelevant, fine-grained/sequential determinism in hardware might be inefficient, a tick is closer to a hardware clock, etc...

In comparison to Lustre:

Very different programming mindset. IIRC, in Lustre you define equations and the system is responsible for keeping them up-to-date/correct. It is a data-flow language (vs control-flow), closer to FRP than Céu/Esterel.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by ratstew on Tuesday January 31, 2017 @02:31PM (#13534340)
The C integration aspect sounds really neat, especially for writing concurrent code on the Arduino!

Thanks for the detailed explanation.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @02:39PM (#13534416)
Yes, we can take advantage of all existing libraries in C/C++ for free.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by junke on Tuesday January 31, 2017 @01:56PM (#13533914)
Céu looks really similar to Esterel. The thesis (http://www.ceu-lang.org/chico/ceu_phd.pdf) has a section titled "III.7 Differences to Esterel". (edit: removed explanations, the other comment is more detailed).
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @02:02PM (#13533989)
Thanks, forgot to mention in the other comment that Céu is actually based on Esterel.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by zzzcpan on Tuesday January 31, 2017 @02:45PM (#13534491)
Was there a particular problem you were trying to solve by creating Ceu? Or was it just to learn things about compilers?

EDIT: found the answer in the paper: "Despite the continuous research in facilitating programming WSNs, most safety analysis and mitigation efforts in concurrency are still left to developers, who must manage synchronization and shared memory explicitly. In this paper, we present a system language that ensures safe concurrency by handling threats at compile time, rather than at runtime."

Re:Show HN: Céu, Structured Synchronous Reactive Programming by pron on Tuesday January 31, 2017 @02:57PM (#13534610)
I'm not the language's creator, but I assume that part of the goal was to bring synchronous programming to the mainstream. Synchronous programming languages are well known in the safety-critical hard realtime world. They're based on a mathematical theory that (as opposed to pure-functional programming) embraces interaction and concurrency, which makes them very suitable for interactive applications (whereas compilers are the natural domain for pure-FP). In addition, synchronous languages are currently the most amenable languages to formal verification. These two reasons are why they're popular and successful in the domain I mentioned. Also, synchronous languages naturally support styles of programming (under research) that are intended to be more natural, and facilitate correct code (in addition to the formal-method-friendliness), such as behavioral programming[1].

BTW, Eve is another synchronous language, although a declarative rather than an imperative one like Céu. It's great to see those time-tested and well-studied ideas finally break out of the safety-critical realtime world.

[1]: http://www.wisdom.weizmann.ac.il/~bprogram/more.html

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @03:13PM (#13534752)
> "part of the goal was to bring synchronous programming to the mainstream"

This was not the original academic goal, but it is now.

We want to offer an imperative alternative to program reactive systems.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by pron on Tuesday January 31, 2017 @03:15PM (#13534772)
Any plans on offering formal methods for Céu?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @03:20PM (#13534808)
Some colleagues are working on an operational semantics of the language (based on the one in the thesis). This will allow us to prove some claims (e.g., reaction termination, bounded memory). Then, we may think about something else. Anything more specific in mind?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by pron on Tuesday January 31, 2017 @03:40PM (#13534978)
Temporal logic verification (via model checking, static analysis, test generation, runtime checks etc.)?
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @03:54PM (#13535114)
That would be interesting.

It seems to be feasible given the language semantics.

We'll definitely investigate it.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @03:06PM (#13534697)
Thanks for the explanation, this is pretty accurate.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @03:00PM (#13534638)
Yes, the problem on how to handle events in soft real-time applications with concurrent activities that affect each other. We initially targeted constrained embedded systems and came with the following design decisions:

- Safe and seamless integration with C (everything in ES uses C). Approach: source-to-source compiler + finalization mechanisms.

- Allow shared memory concurrency (typical in ES with I/O ports and low-level manipulation). Approach: synchronous concurrency + full determinism.

- Small overhead (we target 8-bit micro-controllers). Approach: single-threaded implementation, lexical memory management (no GC).

After investigating the synchronous languages from the '80s (Esterel, Lustre, Signal), we came to the conclusion that we wanted something in the line of Esterel.

The thesis and papers [1] discuss the design decisions in extent.

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

Re:Show HN: Céu, Structured Synchronous Reactive Programming by talles on Wednesday February 01, 2017 @09:36AM (#13540982)
Just a bit of trivia: "lua" means "moon" and "céu" means "sky" in Brazilian Portuguese.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by AlexanderDhoore on Tuesday January 31, 2017 @04:03PM (#13535199)
I've been trying to learn more about synchronous programming languages for a while now. Will definitely look into this.

Does anyone know how I could get my hands on Lustre or Esterel? They are not freely available, or are they? Also any good books or resources are very much appreciated.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by fsantanna on Tuesday January 31, 2017 @04:05PM (#13535218)
You can download Esterel freely:

http://www-sop.inria.fr/esterel-org/files/Html/Downloads/Dow...

(AFAIK, it is not open source though.)

[EDIT] For documentation, see "The Esterel Language Primer":

http://www.rw.cdl.uni-saarland.de/~kaestner/es0203/esterel_p...

Don't know about Lustre.

Re:Show HN: Céu, Structured Synchronous Reactive Programming by AlexanderDhoore on Tuesday January 31, 2017 @04:12PM (#13535277)
Thank you! I'm actually working on my own synchronous language, but it's more in line with Lustre than Esterel. Synchronous dataflow with soft real-time goals. If it starts to look like something decent I'll put it on github.
Re:Show HN: Céu, Structured Synchronous Reactive Programming by ratstew on Tuesday January 31, 2017 @04:35PM (#13535472)
Since you're interested in the implementation of synchronous languages you could also take a look at Quartz [1]. Their book is a fantastic resource about the topic.

[1] http://www.averest.org

Re:Show HN: Céu, Structured Synchronous Reactive Programming by hisham_hm on Tuesday January 31, 2017 @12:22PM (#13532781)
Kudos for the work! The intro video is really nice (pro tip: it is perfectly watchable at 1.25x (or even 1.5x) speed — thanks, YouTube speed settings!)
Re:Show HN: Céu, Structured Synchronous Reactive Programming by flippyhead on Tuesday January 31, 2017 @07:19PM (#13536854)
Great to see this here. I love Ceu. It's a joy to use for the Arduino.