Behaviors and Events

In FRP, there is a distinction between “Behaviors”, which represent continuous values over time, and “Events”, which represent sequence of discrete changes over Time.

A behavior can be easily converted to events and vice versa (a behavior is like a stream of events but the value of the last event is cached and used as the current value of the behavior; an event is like a behavior but the change in the current value is recorded as a change event). Especially because KScript is a dynamically typed language, no the type constraint on them is enforced; one could mix them in the program.

But it still helps to think of the Distinction. Most notably, behaviors have initial values thus they have always values while events don’t have any value until the first change occurs. The way KScript defines behaviors is to provide the initial value and increment either by using the keyword “fby” (meaning ’followed by’ and borrowed from Lucid), or to send startsWith() (borrowed from Flapjax) to a stream to give the initial value.