非纯声明性语言中赋值语义的适当运算符

发布于 2024-08-13 14:00:19 字数 793 浏览 5 评论 0原文

我正在设计一种用于定义信号网络的声明性语言。我想使用变量绑定来表示网络中的节点组。我突然想到,我希望对这些变量进行两种类型的“赋值”。

一方面,变量应该代表一组特定信号运算符的输出。然后可以将该输出附加到另一个输入。这对于将不同的输出定向到不同的位置非常重要,例如:

a, b, c = (SignalA with three outputs)
(SignalB a)
(SignalC c)
(SignalD a)

在这种情况下,将有一个具有三个输出的 SignalA,其中第一个和第三个输出分别链接到 SignalB 和 SignalC,而 SignalD 也链接到 SignalA 的第一个输出信号A. SignalA 只有一个实例。

另一方面,变量应该表示信号操作的通用模式,以便很容易重现通用配置:

a = (SignalA (SignalB))
(SignalC a)
(SignalD a)

在本例中,我希望 a 表示 SignalA 和 SignalB 的组合,并且将其复制作为 SignalC 和 SignalD 的输入。这里有 两个 SignalA 实例。

所以我的问题是,在函数式/声明式编程中,这两种赋值语义是否有通用术语?用我的语言来说,哪个应该得到“=”,另一个的常用运算符是什么? (也许:=?)

我当然意识到,如果每个信号确实代表一个函数,那么这两个信号将是相同的,但在我的情况下,当信号已处理,所以我需要区分这两种情况。

I'm designing a declarative language for defining signal networks. I want to use variable bindings to represent groups of nodes in the network. It occurred to me that there are two types of "assignment" I wish to do for these variables.

On the one hand, a variable should represent the output of a specific group of signal operators. This output can then be attached to another input. This is important for directing different outputs to different places, for example:

a, b, c = (SignalA with three outputs)
(SignalB a)
(SignalC c)
(SignalD a)

In this case there would be a SignalA with three outputs, where the first and third outputs get linked to SignalB and SignalC respectively, and SignalD also gets linked to the first output of SignalA. There is only one instance of SignalA.

On the other hand, a variable should represent a common pattern of signal operations, so that it's easy to reproduce a common configuration:

a = (SignalA (SignalB))
(SignalC a)
(SignalD a)

In this case, I'd like a to represent the composition of SignalA and SignalB, and this is reproduced as the input for SignalC and SignalD. There are two instances of SignalA here.

So my question is, in functional/declarative programming, are there common terms for these two assignment semantics? And in my language, which one should get '=', and what would be a common operator for the other? (perhaps := ?)

I realized of course that if each Signal really represented a pure function, then both of these would be the same, but in my case it's possible for side effects to occur when the signal is processed, so I need to differentiate these two cases.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你没皮卡萌 2024-08-20 14:00:19

已经过了我的睡觉时间,所以我可能没有仔细阅读。但第二种情况是不是类似于匿名函数呢?你的语法看起来已经很像 lisp 了,所以我想知道 lambda 函数的 lisp 快捷语法是否是你想要的。

a = '(SignalA (SignalB))

如果您的用法实际上与 lambda 的含义并不相似,那么它可能会导致更多混乱。

顺便说一句,在第一种情况下,您可以遵循 Perl 对列表赋值左侧的想法:
(a, b, c) = (SignalA with三个输出)

不知道这是否有帮助;除了 Perl 和 C 等命令式语言之外,我的经验并不丰富。

It's past my bed time, so I may not be reading carefully enough. But is the second case similar to an anonymous function? Your syntax looks lisp-like already, so I wonder if lisp's shortcut syntax for the lambda function might be what you want.

a = '(SignalA (SignalB))

If your usage is not actually similar in meaning to lambda, then it will probably cause more confusion.

BTW, in the first case, you could follow Perl's idea for the left side of a list assignment:
(a, b, c) = (SignalA with three outputs)

No idea if this will be helpful; I'm not that experienced outside of imperative languages like perl and C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文