Setting Values into Streams

To leave room for exploration and tools such as inspectors, the notion of “setting” or “assigning” a value into a stream exists in the KSWorld. For example, as shown in the examples of section 4.1, the stream of values that represents the position of a Box cannot be purely defined by a function of other streams, as one may want to move the Box via a halo, an inspector or other external means. (In a self-sustaining system that KSWorld is aspiring to, different kinds of inspectors may be created after the Box was created.)

To support such actions, a stream supports an operation called set.The set operation simply takes an argument and stores it into the stream. The dependents of the stream will be evaluated in the next time step.

This concept meshes nicely with the “constant stream”, which has no dependency and just represents a constant value. However, nothing would be totally constant in a self-sustaining system. Again, for the example of the stream that represents the position of a Box, such a Box is typically born as “vanilla”, meaing with no behavior attached, thus its position would be considered constant. However, such a Box’s position sometimes has to be changed to support the notion of direct manipulation and editing from a meta tool. Such manipulation can be easily supported by setting new values into the “constant” stream, and the dependents of the position can be naturally resolved by the same dependency evaluation mechanism.

We call such a constant stream (but that still supports set) a “value stream”. To create such a stream, there is a method called streamOf() for EventStream. It takes one argument and creates a constant stream with the argument or, in other words, creates a value stream with the argument as the initial value.

[…]