views:

62

answers:

1

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.

A: 

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.

Peter Cordes
The tick ' is actually for quoted lists, and not for lambdas. A LISP lambda would look more like (lambda (x) x)if I'm not too rusty :)
Steven Schlansker
Thanks for trying, but I think that's not quite right. This is a declarative language---the program is not /executed/, but is actually a script that sets up a signal network, which is /then/ executed. In my first case, the output of a single unit is replicated to two locations, and in the second case the definition of a set of units is replicated. They are different cases because if the unit has internal state (is non-pure) you will get very different semantics. This is not quite like lambda functions, I think, because you can't pass them around at run time.
Steve
On second thought though, the basic idea of using some kind of quoting operator is not necessarily a bad one..
Steve