2

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?

Databyte
  • 1,420
  • 1
  • 15
  • 24
  • So how would it know that you can edit the value of the first TextBox and it doesn't get re-set to 5 every time you re-evaluate these expressions? – uliwitness Sep 26 '14 at 00:39
  • It's like an imperative Haskell. Perhaps [Elephant 2000](http://www-formal.stanford.edu/jmc/elephant/elephant.html) supports this. – Sylwester Sep 26 '14 at 02:19
  • @uliwitness: The expression is only evaluated once, at the beginning of the program. after that the dependency is known by the (lets say) vm and only recalculated, when a dependent value changes. So after the start of program, the vm will be in a "stable" state and do nothing, until one of two things happen: 1. an event occurs or 2. a bound external value changes. In both cases the program has to be updated to a new stable state. It's like haskell, until an event occurs, in which case it has and should have massive side effects. – Databyte Sep 26 '14 at 08:17
  • 1
    Verilog looks quite like that. It's mainly for hardware simulation, though. – phipsgabler Sep 26 '14 at 10:04
  • 1
    Look for "reactive programming". – molbdnilo Sep 26 '14 at 11:18

3 Answers3

3

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

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
0

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.

uliwitness
  • 8,532
  • 36
  • 58
0

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.

Jafar Rasooli
  • 3,437
  • 2
  • 14
  • 13