Pin*_*juh 19 language-features dataflow operators
我目前正在为连续环境中的编程开发一种新语言(将其与电气工程相比较),并且我对某种语言结构有一些想法.
让我通过解释然后按定义解释这个特征:
x = a U b;
Run Code Online (Sandbox Code Playgroud)
x变量在哪里,a而且b是其他变量(或静态值).这就像是a和之间的结合b; 没有重复,也没有具体的订单.
with(x) {
// regular 'with' usage; using the global interpretation of "x"
x = 5;
// effectively will do:
// x = a U b U 5;
// a = 5;
// b = 5;
// Thus, when "a" or "b" changes, "x" is still equal to "5".
}
with(x = a) {
// this code block is executed when the "x" variable
// has the "a" variable assigned. All references in
// this code-block to "x" are references to "a". So saying:
x = 5;
// would only change the variable "a". If the variable "a"
// later on changes, x still equals to 5, in this fashion:
// 'x = a U b U 5;'
// '[currentscope] = 5;'
// thus, 'a = 5;'
}
with(x = b) {
// same but with "b"
}
with(x != a) {
// here the "x" variable refers to any variable
// but "a"; thus saying
x = 5;
// is equal to the rewriting of
// 'x = a U b U 5;'
// 'b = 5;' (since it was the scope of this block)
}
with(x = (a U b)) {
// guaranteed that "x" is 'a U b'; interacting with "x"
// will interact with both "a" and "b".
x = 5;
// makes both "a" and "b" equal to 5; also the "x" variable
// is updated to contain:
// 'x = a U b U 5;'
// '[currentscope] = 5;'
// 'a U b = 5;'
// and thus: 'a = 5; b = 5;'.
}
// etc.
Run Code Online (Sandbox Code Playgroud)
在上文中,执行所有代码块,但"范围"在每个块中改变如何x解释.在第一个块中,x保证是a:因此与x该块内部的交互将进行交互a.第二个和第三个代码块在这种情况下只相等(因为not a:那时只剩下b).最后一个块保证x至少是a或b.
更多; U不是"按位或运算符",但我称之为"和/或" - 运算符.它的定义是:
"U" = "and" U "or"
Run Code Online (Sandbox Code Playgroud)
(在我的博客http://cplang.wordpress.com/2009/12/19/binop-and-or/上,有关此运算符的更多(数学)背景信息.它基于集合松散.使用不同的语法,在这个问题中改变了它.)
更新:更多示例.
print = "Hello world!" U "How are you?"; // this will print
// both values, but the
// order doesn't matter.
// 'userkey' is a variable containing a key.
with(userkey = "a") {
print = userkey; // will only print "a".
}
with(userkey = ("shift" U "a")) {
// pressed both "shift" and the "a" key.
print = userkey; // will "print" shift and "a", even
// if the user also pressed "ctrl":
// the interpretation of "userkey" is changed,
// such that it only contains the matched cases.
}
with((userkey = "shift") U (userkey = "a")) {
// same as if-statement above this one, showing the distributivity.
}
x = 5 U 6 U 7;
y = x + x; // will be:
// y = (5 U 6 U 7) + (5 U 6 U 7)
// = 10 U 11 U 12 U 13 U 14
somewantedkey = "ctrl" U "alt" U "space"
with(userkey = somewantedkey) {
// must match all elements of "somewantedkey"
// (distributed the Boolean equals operated)
// thus only executed when all the defined keys are pressed
}
with(somewantedkey = userkey) {
// matches only one of the provided "somewantedkey"
// thus when only "space" is pressed, this block is executed.
}
Run Code Online (Sandbox Code Playgroud)
Update2:更多示例和更多上下文.
with(x = (a U b)) {
// this
}
// can be written as
with((x = a) U (x = b)) {
// this: changing the variable like
x = 5;
// will be rewritten as:
// a = 5 and b = 5
}
Run Code Online (Sandbox Code Playgroud)
一些背景信息:我正在构建一种"与时间无关"的语言,就像Java是"平台无关的".语言中陈述的所有内容都是"按原样",并且不断积极执行.这意味着; 程序员不知道以什么顺序(除非使用结构明确声明)元素,也不知道何时执行语句.语言与"时间" - 概念完全分开,即它不断执行:
with(true) {
a = 0; // only runs once (lazy execution)
}
with(a < 5) {
a++;
} // this is a loop-structure;
// how and when it's executed isn't known however.
with(a) {
// everytime the "a" variable changes, this code-block is executed.
with(true) {
b = 3; // only 5 times (again lazy execution, but it's a sub-with)
}
with(b < 2) { // dependent on "b"
// runs only 3 times * 5 times = 15 times.
}
with(b > 1) { // dependent on "b"
b = b - 1; // runs 4 times * 5 times = 20 times.
}
}
Run Code Online (Sandbox Code Playgroud)
更新3:
在思考了这种语言特征的类型之后; 它与Netbeans Platform的Lookup非常相似,其中每个"with" - 陈述是一个同步代理,正在处理对象的特定"过滤器".这是基于变量的(基本上是完全相同的;只是一种识别对象的不同方式),而不是基于类型.
我非常感谢大家为我提供了非常有见地的信息和链接/提示我可以研究的重要主题.谢谢.
我不知道这个结构是否已经存在,所以这是我的问题:这个语言功能是否已经存在?
老实说,我发现你的解释和示例很难理解(更新:你的博客好多了,阅读其中的Statement Ordering我更加确信你的目标是一种数据流编程形式)。
但是,您的最终描述:
语言中陈述的一切都是“按原样”,并且不断地积极执行。这意味着; 程序员不知道元素的顺序(除非使用构造明确说明),也不知道语句何时执行。该语言与“时间”概念完全分离,即它是连续执行的:例如,说“a”是“b”并且“b”是“a”是一个简单的循环结构。
..让我认为您正在搜索的通用术语是数据流编程(即使在更简单的数据流编程实例中不允许循环)。引用维基百科:
Dataflow是一种软件架构,其理念是更改变量的值应自动强制重新计算取决于其值的变量的值。
Icon的目标导向求值在范围上受到更多的限制(参见这个Icon简介:目标导向求值机制隐含的回溯仅限于它发生的表达式)。
另请参阅 Stackoverflow 上的这个问题:数据流编程语言。
更新: Pindatjuh 在评论中询问“您也可以评论一下,这种语言是否是数据流主题的新变体? ”。我认为是的,但问题实际上是关于定义以及共识。在最近关于数据流语言的调查《数据流编程语言的进展》(发表于ACM 计算调查,第 36 卷,第 1 期,2004 年 3 月)中,作者写道(第 10 页):
构成数据流语言的最佳功能列表由 Ackerman [1982] 提出,并由 Whiting 和 Pascoe [1994] 以及 Wail 和 Abramson [1995] 重申。该列表包括以下内容:
- 免受副作用的影响,
- 效应局部性,
- 数据依赖相当于调度,
- 变量的单一赋值,
- 由于特征 1 和 4,迭代的不寻常表示法,
- 程序中缺乏历史敏感性。
我没有读完你的全部博客,只是简单地浏览了一下,所以你比我更有资格判断你的编程语言(无论如何,这是一个移动的目标)。
更新:我无意识地错过了你的问题中的“新”这个词“ ……这种语言是……的新变体”。这是一项艰巨的任务:需要考虑迄今为止发明的所有数据流语言,并仔细检查它们的语义细节,以发现方法中的新颖之处。我现在肯定没有必要的知识。