我有一些时间考虑了一种基于事件的编程语言。我的意思是一种语言,当您更改因变量时,每个变量都会更新。例如,考虑以下终端应用程序的伪代码:
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)
}
按 enter 将打印b的值。但结果将仅在前五秒内为10 ,因为之后a将更新为10并且在接下来的五秒内b将等于15,因为b取决于a。
这个概念当然会带来一些问题,但它也提供了一些好处。例如,想象一个 GUI 应用程序(通常用事件编程),它显示两个输入框和两个数字相加的结果:
------------- -------------
| 5 | + | 6 | = 11
------------- -------------
它可以通过以下方式编程:
// 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) }
而已。它有点像 excel,但有真正的编程。有这样的编程语言吗?或者类似的东西?