<p>
A polymorphic adder/subtractor.
This adder has two input ports, both of which are multiports,
and one output port, which is not.
The types on the ports are undeclared and will be resolved by
the type resolution mechanism. Data that arrives on the
input port named <i>plus</i> will be added, and data that arrives
on the input port named <i>minus</i> will be subtracted.
Any token type supporting addition and subtraction can be used.
In most domains, either input port can be left unconnected.
Thus, to get a simple adder (with no subtractor), just leave the
<i>minus</i> input unconnected.</p>
<p>
The <i>plus</i> input port will typically resolve to the least upper bound
of the types presented to it. Thus, for example, if one input channel
comes from a source of type BooleanToken and another comes from a source
of type IntToken, the resolved type will be StringToken, and addition
will be that implemented in StringToken (which concatenates strings).
Notice that StringToken does not support subtraction, so if any
inputs are presented to the <i>minus</i> port, an exception will
be thrown at run time.</p>
<p>
Currently, the type system is quite liberal about the resolved
types it will permit at the inputs. In particular, it may permit the
<i>plus</i> and <i>minus</i> inputs to resolve to types that cannot in fact
be subtracted. In these cases, a run-time error will occur.
In the future, we hope that the type system will intercept such errors
before run time.</p>
<p>
This actor does not require that each input
channel have a token upon firing. It will add or subtract available
tokens at the inputs and ignore the channels that do not have tokens.
It consumes at most one input token from each port.
If no input tokens are available at all, then no output is produced.</p>
Yuhong Xiong and Edward A. Lee
$Id: AddSubtract.java 70398 2014-10-22 23:44:32Z cxh $
Ptolemy II 0.3
Green (eal)
Green (bilung)
Input for tokens to be subtracted. This is a multiport, and its
type is inferred from the connections.
Output port. The type is inferred from the connections.
Input for tokens to be added. This is a multiport, and its
type is inferred from the connections.