Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top