Databyte
Databyte

Reputation: 1481

Does an asynchronous-event-based programing languages exists?

I had some time and thought about an event-based programming language. By that I mean a language where every variable is updated, when you change a dependent variable. For example consider the following pseudo-code for a terminal-application:

int a = 5
int b = a + 5

// event which is called every 5 seconds
every 5 seconds =>
{
     // update a by adding 5
     a << a + 5
}

// event which is called when the user presses enter
on enter =>
{
    println("b = " + b)
}

Pressing enter will print the value of b. But the result will be 10 only for the first five seconds, because after that a will be updated to 10 and for the next five seconds b will equal 15, because b depends on a.

This concept will bring certain problems, of course, but it also offers some benefits. Imagine for example a GUI-application (which is normally programmed with events), which shows two inputboxes and the result of adding the two numbers:

-------------     -------------
| 5         |  +  | 6         | = 11
-------------     -------------

It could be programmed in the following way:

// two inputboxes and a label
Textbox tb1 = new TextBox() { format = "numeric", value = 5 }
Label lbl1_plus = new Label() { value = "+" }
Textbox tb2 = new TextBox() { format = "numeric", value = 6 }

// and the result
Label lbl1_plus = new Label() { value = "= " + (tb1.value + tb2.value) }

Thats it. It is a little bit like excel, but with real programming. Is there a programming language like this? Or something similar?

Upvotes: 2

Views: 190

Answers (3)

Jafar Rasooli
Jafar Rasooli

Reputation: 3527

simple choice is using Reactive programming. reactive programming is combination of functional programming and event based programming. there are a lot of utility functions witch let you define events or actions based on smaller events. for example in your case you can define an event AE every time variable A changes. based on that you can trigger a sequence witch adds A to B and prints it. you can see list of its implementation in different languages at http://reactivex.io/languages.html .

more complex situations could be handled through use of CEP (complex event processing) tools. CEP lets you define basic events and describe complex patterns of these events and capture their occurance. although this tools are at the begining of their life, and maybe there is not enough mature one, but their specification meet your mentioned requirements.

Upvotes: 0

Norman Ramsey
Norman Ramsey

Reputation: 202505

Something vaguely similar: look into Functional Reactive Programming in general and into Elm in particular.

Upvotes: 3

uliwitness
uliwitness

Reputation: 8791

I haven't seen this exact language, but it seems a bit like a combination of aspects of Prolog and and Inform. I.e. functional and constraint-based programming.

Upvotes: 0

Related Questions