这种语言功能已经存在吗?
我目前正在开发一种新的语言,用于在连续环境中进行编程(将其与电气工程进行比较),并且我对某种语言的构造有了一些想法。
让我通过解释和定义来解释该功能:
x = a U b;
其中 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.
在上面,所有代码块都被执行,但是每个块中的“范围”改变了 x
的解释方式。在第一个块中,x
保证为 a
:因此与该块内的 x
交互将在 a
上交互>。仅在这种情况下,第二个和第三个代码块才相等(因为不是a
:那么只剩下b
)。最后一个块保证x
至少是a
或b
。
此外; U
不是“按位或运算符”,但我将其称为“和/或”运算符。它的定义是:(
"U" = "and" U "or"
在我的博客上, 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.
}
更新2:更多示例和更多上下文。
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
}
一些背景信息:我正在构建一种“与时间无关的语言” ”,就像 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.
}
}
更新3:
在思考该语言特征的类型之后;它与 Netbeans 平台的 Lookup 非常相似,其中每个“with”语句都是一个同步代理,作用于其特定的对象“过滤器”。它不是基于类型,而是基于变量(基本上完全相同;只是识别对象的方式不同)。
我非常感谢你们所有人为我提供了非常有见地的信息以及我可以研究的重要主题的链接/提示。谢谢。
我不知道这种结构是否已经存在,所以这就是我的问题:这种语言功能是否已经存在?
I'm currently developing a new language for programming in a continuous environment (compare it to electrical engineering), and I've got some ideas on a certain language construction.
Let me explain the feature by explanation and then by definition:
x = a U b;
Where x
is a variable and a
and b
are other variables (or static values). This works like a union between a
and b
; no duplicates and no specific order.
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.
In the above, all code-blocks are executed, but the "scope" changes in each block how x
is interpreted. In the first block, x
is guaranteed to be a
: thus interacting with x
inside that block will interact on a
. The second and the third code-block are only equal in this situation (because not a
: then there only remains b
). The last block guarantees that x
is at least a
or b
.
Further more; U
is not the "bitwise or operator", but I've called it the "and/or"-operator. Its definition is:
"U" = "and" U "or"
(On my blog, http://cplang.wordpress.com/2009/12/19/binop-and-or/, there is more (mathematical) background information on this operator. It's loosely based on sets. Using different syntax, changed it in this question.)
Update: more examples.
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.
}
Update2: more examples and some more context.
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
}
Some background information: I'm building a language which is "time-independent", like Java is "platform-independant". Everything stated in the language is "as is", and is continuously actively executed. This means; the programmer does not know in which order (unless explicitly stated using constructions) elements are, nor when statements are executed. The language is completely separated from the "time"-concept, i.e. it's continuously executed:
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.
}
}
Update 3:
After pondering on the type of this language feature; it closely resemblances Netbeans Platform's Lookup, where each "with"-statement a synchronized agent is, working on it's specific "filter" of objects. Instead of type-based, this is variable-based (fundamentally quite the same; just a different way of identifiying objects).
I greatly thank all of you for providing me with very insightful information and links/hints to great topics I can research. Thanks.
I do not know if this construction already exists, so that's my question: does this language feature already exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
老实说,我发现你的解释和例子很难理解(更新:你的博客好多了,阅读Statement Ordering 那里我更加确信您的目标是数据流编程形式)。
但是,您的最终描述:
..让我认为您正在搜索的通用术语是数据流编程(即使在更简单的数据流编程实例中不允许使用循环)。引用维基百科:
反应式编程 和 函数式响应式编程是同一主题的变体。
Icon 的目标导向评估范围更受限制(请参阅此 Icon 简介:目标导向求值机制所隐含的回溯仅限于它发生的表达式)。
另请参阅 Stackoverflow 上的此问题:数据流编程语言。
更新: Pindatjuh 在评论中询问“你也可以评论一下,这种语言是否是数据流主题的新变体?”。我认为是的,但问题实际上是关于定义以及共识。在最近一项有关数据流语言的调查中,数据流编程语言的进步< /a>(发布于ACM 计算调查,第 36 卷,第 1 期,2004 年 3 月),作者写道(第 10 页):
我没有读完你的全部博客,只是简单地浏览了一下,所以你比我更有资格判断你的编程语言(无论如何,这是一个移动的目标)。
更新:我无意中错过了您问题中的“新”一词“...这种语言是...的新变体”。这是一项艰巨的任务:需要考虑迄今为止发明的所有数据流语言,并仔细检查它们的语义细节,以发现方法中的新颖之处。我现在肯定没有必要的知识。
I honestly find your explanation and examples difficult to follow (update: your blog is much better and reading Statement Ordering there I'm even more convinced that you are aiming at a form of dataflow programming).
However, your final description:
.. induces me to think that the general term that you are searching for is dataflow programming (even if loops are not permitted in the more simple instances of dataflow programming). Quoting from Wikipedia:
Reactive programming and functional reactive programming are, as I understand them, variations on the same theme.
Icon's goal-directed evaluation is more restricted in scope (see this A Brief Introduction to Icon: The backtracking implied by the goal-directed evaluation mechanism is limited to the expression in which it occurs).
See also this question on Stackoverflow: Dataflow Programming Languages.
Update: Pindatjuh asks in comments "Can you also comment, whether this language is a new variation on the theme of dataflow?". I think so, but the question is really about definitions and so about consensus. In a recent survey about dataflow languages, Advances in dataflow programming languages (published in ACM Computing Surveys, Volume 36 , Issue 1, March 2004), authors wrote (page 10):
I haven't read all your blog but just perused it lightly, so you are more qualified than me to judge about your programming language (which is a moving target anyway).
Update: I unconsciously missed the word "new" in your question "... this language is a new variation on...". It is an hard task: one needs to consider all the dataflow languages invented until now and carefully examine their semantics in detail to spot a novelty in your approach. I surely haven't the necessary knowledge at this time.
我发现这很难理解,但你的意思是:
将是语法糖相当于:
在博客文章中你给出了这个例子:
所以该表达式的类型是一对整数,每个值分别为 3 和 4代表可能的值之一。所以我们也可以说:
这两者都将评估为 true。因此,运算符
==
可以将一个值与一种值向量进行比较,如果向量中的任何值等于第一个值,则该运算符将为true
。这可以使用几种语言中的运算符重载来实现(尽管您必须将简单值显式“提升”到包装类型中,然后才能对其进行操作)。
它实际上不是与两个集合的并集相同,并且 == 被解释为“是……的成员”吗?运算符喜欢 + 被提升,这样它们就适用于集合中的所有成员。
如果您执行 (1|2) + (4|8),您将得到相当于 (5|9|6|10) 的结果,因为这是四种可能的结果。
好的,从您添加的进一步示例中,我发现
==
实际上要求左侧和右侧是同一组,而不仅仅是重叠。但我仍然觉得你的|
只是两个集合的并集。这意味着什么(或意味着什么)将取决于您对语言的所有其他功能进行的处理集合的操作。关于您的发言:
您是否仔细研究过像 Haskell 这样的纯函数式语言?程序是一系列没有已知执行顺序的定义,您只能编写没有副作用的纯函数,因此解释器可以按照自己喜欢的方式排序执行,只要真正需要时值可用即可。
更新:
您在问题中添加了以下内容:
我想知道您认为这会有何启发!
问题是,前两个版本在 if 下有一个代码块。因此,如果第三个扩展版本有两个块,那么它们必须是同一个块。换句话说,这只是另一种写法:
Where ||是传统的布尔 OR。这正是我首先问的问题。
好吧,再一次...您现在已经更改了语法以表明您正在执行并集和交集。但是:
所以
I
意味着取两个集合的交集...但是if
在什么情况下执行代码块?如果交集非空?或者I
实际上是在问“该集合的所有成员都是左边集合的右侧成员吗”并且有提示userkey
在范围内被替换该块的另一个值实际上只是右侧的集合。我要去睡觉了。
I'm finding this hard to follow, but do you mean that:
will be syntax sugar equivalent to:
On the blog post you give this example:
So the type of that expression is a pair of integers with the values 3 and 4, each representing one of the possible values. So we can also say:
and both of those would evaluate to true. So the operator
==
can compare a value with a kind of vector of values and will betrue
if any of the values in the vector are equal to the first value.This could be implemented using operator overloading in a few languages (although you'd have to explicitly "lift" simple values into a wrapper type before you could operate on them).
Isn't it effectively the same as the union of two sets, and with == interpreted as "is a member of"? And operators like + being lifted so they apply to all the members of the set.
And if you did (1|2) + (4|8) you'd get the equivalent of (5|9|6|10), because those are the four possible outcomes.
Okay, from further examples you added, I see that
==
in fact requires the left and right sides to be the same set, rather than merely overlapping. But I still get the impression that your|
is simply the union of two sets. What this entails (or means) will depend on what you do to all the other features of your language to deal with sets.Regarding your statement:
Have you looked much at pure functional languages like Haskell? Programs are a series of definitions with no known order of execution, you can only write pure functions with no side-effects, and hence the interpreter can order execution however it likes as long as values are available when really needed.
Update:
You added this to your question:
I wonder how you think that's going to be illuminating!
The thing is, the first two versions have one block of code under the if. So if the third expanded version has two blocks, they must be the same block. In other words, this is just another way of writing:
Where || is the traditional boolean OR. Which is exactly the question I first asked.
Okay, one more time... You've now changed the syntax to indicate that you're doing unions and intersections. But then:
So
I
means take the intersection of the two sets... butif
executes the code block under what circumstances? If the intersection is non-empty? Or isI
in fact asking "are all the members of the set on the right members of the set on the left" And there are hints thatuserkey
is replaced in the scope of the block by another value which actually just the set on the right.I'm going to bed.
您的示例和数学都可以使用一些工作,但在您博客上的至少一个示例中,您对
|
的使用非常类似于同一运算符的使用(称为“交替”,我相信)图标编程语言。如果你打算在这个领域进行语言设计,你绝对应该阅读
Your examples and your math could both use some work, but in at least one of the examples on your blog, your use of
|
closely resembles the use of the same operator (there called "alternation", I believe) in the Icon programming language.If you're going to commit language design in this area, you should definitely read about
C# 肯定不具备您所描述的功能。你所说的似乎有点让人想起罗宾·米尔纳的 pi 演算;这一切都是为了定义一种用于描述并发进程的语言。如果您还没有的话,您可以考虑对此进行一些研究。
C# certainly doesn't have the features you are describing. What you're talking about seems somewhat reminiscent of Robin Milner's pi calculus; it's all about defining a language for describing concurrent processes. You might consider doing some research into it if you haven't already.
您的语言功能类似于 Perl 6 中的 连接。
在 Perl 5 中,有 Quantum::Superpositions 模块。
Your language feature resembles junctions in Perl 6.
In Perl 5, there's the Quantum::Superpositions module.
你应该发明自己的符号,即使只是为了例子。
看起来您正在尝试根据范围定义的需要动态更改变量引用。这是一种非常微妙的技术,我不知道任何语言可以做到这一点。尽管我可以看到闭包、生成器和回溯的相似之处,但大多数语言都要求您明确执行此操作。
您能解释一下推动这种不寻常方法的背景吗?您的博客链接不是很有帮助。并且术语“连续编程”也没有定义或解释。
更新:
好的,看看您编辑的示例,我可以指出 Icon 具有类似的内容。这并不完全是您所要求的,而且并不常见,但它看起来很接近并且定义得更好。这称为目标导向评估。
许多语言元素提供或允许您构建一个生成器,如果需要,它可以提供许多替代方案。您的示例和 Icon 之间的主要区别是您必须为语言提供上下文才能继续尝试替代方案。赋值不能做到这一点,但比较可以。一旦生成器耗尽了它可以提供的值,它就会失败。这也是普通比较的工作原理,整个功能很好地集成到更广泛的语言中。 (我有时将其描述为微型异常。)
Python 和 Ruby 有一个
yield
机制,该机制非常相似,并且可以说受到 Icon 生成器的影响。You should have invented your own symbols, even just for the example.
It looks like you're trying to do variable references that dynamically change as the scope definition requires. That is a very subtle technique and I don't know any language that does it. Most languages require you to do this explicitly although I can see similarities with closures, generators and back-tracking.
Could you explain the context driving this unusual method? Your blog link was not very helpful. And the term 'continuous programming' is not defined or explained, either.
Update:
Okay, looking at your edited example, I can point to Icon as having something similar. It is not quite what you think you're asking for, and it is not common, but it seems close and it much better defined. It is called Goal-Directed Evaluation.
Many language elements provide or allow you to construct a generator which can give a number of alternatives if asked. The main difference between your example and Icon you have to provide a context for the language to keep trying alternatives. Assignment doesn't do it, but a comparison will. Once a generator runs out of values it can supply, it fails. This is also how ordinary comparison works and the whole feature integrates nicely into the wider language. (I sometimes describe this as being like miniature exceptions.)
Python and Ruby have a
yield
mechanism which is very similar and arguably influenced by Icon's generators.我建议你不要添加该语言功能。如果您进行如下“测试”,程序员会非常不清楚 x 的含义会发生变化:
I advise you not to add that language feature. It would be very unclear to the programmer that the meaning of x changes if you do a "test" like:
Inform IF 创作语言具有此功能。来自DM:
它并没有真正流行起来不过,更进一步,因为解析起来有点奇怪(您必须将每个
or
/|
运算符与特定所有者==
/< code>!= 比较器),在现代脚本语言中,很容易用以下内容替换:(Python 示例。)
The Inform IF-authoring language had this feature. From the DM:
It hasn't really caught on much further, though, as it's a bit weird to parse (you have to associate each
or
/|
operator with a particular owner==
/!=
comparator), and in modern scripting languages it's easy to replace with something like:(Python example.)
您似乎同时探索了几个想法:
5 | 的操作。 6 | 7
::list:: + ::list::
::scalar:: == ::list::
实现了“is an element of”,依此类推,我不知道有哪个语法功能结合了这些想法,但后来我没有真正丰富的经验...
You seem to be poking around several ideas at once:
5 | 6 | 7
::list:: + ::list::
::scalor:: == ::list::
implements "is an element of", and so onI'm not aware of a single syntaxtical feature that combines those idea, but then I don't have really wide experience...
as3 中存在“with”:
The "with" exist in as3: