TeSSLa Standard Library for TeSSLa 1.1.0

ANCHORTypes

Fundamental types and primitive constants

ANCHORType Bool

Bool

A Boolean can be either true or false

ANCHORType Int

Int

Integer. The maximal and minimal values depend on the TeSSLa engine. The TeSSLa software backend uses BigInt, i.e. every integer can be represented

ANCHORType Float

Float

Float. The data range depends on the TeSSLa engine. The TeSSLa software backend uses a 64-bit IEEE-754 floating point number

ANCHORType String

String

String can store arbitrary long character sequences

ANCHORType Unit

Unit

() is the only value of type Unit, i.e. this type can be used to represent events without values.

ANCHORType Events

Events[T]

Basic type for streams

ANCHORAnnotation @liftable

@liftable

Functions annotated with this annotation can be used on streams which will be equivalent to wrapping their call with slift.

ANCHORtrue

true: Bool

A Boolean value representing that a given proposition is true

ANCHORfalse

false: Bool

A Boolean value representing that a given proposition is false

ANCHOROperators

For every function defined in the operator module there exists a special operator syntax which can be used to call the function using an infix operator.

ANCHOROperators.not

@liftable
not(arg: Bool): Bool

Operator usage: !x

Boolean complement

ANCHOROperators.ite

@liftable
ite[T](cond: Bool, thenCase: T, elseCase: T): T

Operator usage: if c then a else b

If-Then-Else

ANCHOROperators.and

@liftable
and(lhs: Bool, rhs: Bool): Bool

Operator usage: a && b

Boolean conjunction

ANCHOROperators.or

@liftable
or(lhs: Bool, rhs: Bool): Bool

Operator usage: a || b

Boolean disjunction

ANCHOROperators.eq

@liftable
eq[T](lhs: T, rhs: T): Bool

Operator usage: a == b

Equivalence on arbitrary data types. On complex data structures this operator checks the object's identity. Note, that this operator is defined as @liftable, so it does neither check the equivalence nor the identity of streams, but applies the operator on two streams using the signal semantics.

ANCHOROperators.neq

@liftable
neq[T](lhs: T, rhs: T): Bool

Operator usage: a != b

Non-Equivalence on arbitrary data types. On complex data structures this operator checks the object's identity. Note, that this operator is defined as @liftable, so it does neither check the equivalence nor the identity of streams, but applies the operator on two streams using the signal semantics.

ANCHOROperators.gt

@liftable
gt(lhs: Int, rhs: Int): Bool

Operator usage: a > b

Returns true if a is strictly greater than b

ANCHOROperators.lt

@liftable
lt(lhs: Int, rhs: Int): Bool

Operator usage: a < b

Returns true if a is strictly lower than b

ANCHOROperators.geq

@liftable
geq(lhs: Int, rhs: Int): Bool

Operator usage: a >= b

Returns true if a is greater than or equal to b

ANCHOROperators.leq

@liftable
leq(lhs: Int, rhs: Int): Bool

Operator usage: a <= b

Returns true if a is lower than or equal to b

ANCHOROperators.fgt

@liftable
fgt(lhs: Float, rhs: Float): Bool

Operator usage: a >. b

Returns true if a is strictly greater than b

ANCHOROperators.flt

@liftable
flt(lhs: Float, rhs: Float): Bool

Operator usage: a <. b

Returns true if a is strictly lower than b

ANCHOROperators.fgeq

@liftable
fgeq(lhs: Float, rhs: Float): Bool

Operator usage: a >=. b

Returns true if a is greater than or equal to b

ANCHOROperators.fleq

@liftable
fleq(lhs: Float, rhs: Float): Bool

Operator usage: a <=. b

Returns true if a is lower than or equal to b

ANCHOROperators.add

@liftable
add(lhs: Int, rhs: Int): Int

Operator usage: a + b

Returns the sum of two integers

ANCHOROperators.sub

@liftable
sub(lhs: Int, rhs: Int): Int

Operator usage: a - b

Returns the difference of two integers

ANCHOROperators.mul

@liftable
mul(lhs: Int, rhs: Int): Int

Operator usage: a * b

Returns the multiplication of two integers

ANCHOROperators.div

@liftable
div(lhs: Int, rhs: Int): Int

Operator usage: a / b

Returns the division of two integers

ANCHOROperators.mod

@liftable
mod(lhs: Int, rhs: Int): Int

Operator usage: a % b

Returns the remainder of two integers

ANCHOROperators.negate

@liftable
negate(arg: Int): Int

Operator usage: -a

Unary minus on integers

ANCHOROperators.bitand

@liftable
bitand(lhs: Int, rhs: Int): Int

Operator usage: a & b

Bitwise AND on integers

ANCHOROperators.bitor

@liftable
bitor(lhs: Int, rhs: Int): Int

Operator usage: a | b

Bitwise OR on integers

ANCHOROperators.bitxor

@liftable
bitxor(lhs: Int, rhs: Int): Int

Operator usage: a ^ b

Bitwise XOR on integers

ANCHOROperators.bitflip

@liftable
bitflip(arg: Int): Int

Operator usage: ~a

Bitflip on integers

ANCHOROperators.leftshift

@liftable
leftshift(lhs: Int, rhs: Int): Int

Operator usage: a << b

Arithmetic left shift on integers

ANCHOROperators.rightshift

@liftable
rightshift(lhs: Int, rhs: Int): Int

Operator usage: a >> b

Arithmetic right shift on integers

ANCHOROperators.fadd

@liftable
fadd(lhs: Float, rhs: Float): Float

Operator usage: a +. b

Returns the sum of two floats

ANCHOROperators.fsub

@liftable
fsub(lhs: Float, rhs: Float): Float

Operator usage: a -. b

Returns the difference of two floats

ANCHOROperators.fmul

@liftable
fmul(lhs: Float, rhs: Float): Float

Operator usage: a *. b

Returns the multiplication of two floats

ANCHOROperators.fdiv

@liftable
fdiv(lhs: Float, rhs: Float): Float

Operator usage: a /. b

Returns the division of two floats

ANCHOROperators.fnegate

@liftable
fnegate(arg: Float): Float

Operator usage: -.a

Unary minus on floats

ANCHORPrimitiveFunctions

Functions for primitive types

ANCHORmax

@liftable
max(a: Int, b: Int): Int

Compute the maximum of two integer values.

ANCHORmin

@liftable
min(a: Int, b: Int): Int

Compute the minimum of two integer values.

ANCHORtoString

@liftable
toString[T](arg: T): String

Converts any type into its typical string representation

ANCHORpow

@liftable
pow(base: Float, exponent: Float): Float

Returns the value of the first argument raised to the power of the second argument.

ANCHORlog

@liftable
log(x: Float, base: Float): Float

Returns the logarithm to base base of x

ANCHORsin

@liftable
sin(x: Float): Float

Returns the trigonometric sine of an angle x in radians. Special cases:

ANCHORcos

@liftable
cos(x: Float): Float

Returns the trigonometric cosine of an angle in radians. Special cases:

ANCHORtan

@liftable
tan(x: Float): Float

Returns the trigonometric tangent of an angle in radians. Special cases:

ANCHORatan

@liftable
atan(x: Float): Float

Returns the arc tangent of a value; the returned angle is in the range -π/2 through π/2. Special cases:

ANCHORintToFloat

@liftable
intToFloat(x: Int): Float

Converts the given integer to a float.

ANCHORfloatToInt

@liftable
floatToInt(x: Float): Int

Converts the given float to an integer without

ANCHOROption

Optional values

ANCHOROption.map

map[T, U](opt: Option[T], f: ((T) => U): Option[U]

ANCHOROption.flatMap

flatMap[T, U](opt: Option[T], f: ((T) => Option[U]): Option[U]

ANCHOROption.map2

map2[T, U, V](opt1: Option[T], opt2: Option[U], f: ((T, U) => V)

ANCHOROption.toSet

@liftable
toSet[T](option: Option[T]): Set[T]

ANCHORType Option

Option[T]

Represents optional values. Instances of Option are either an instance of Some or None

ANCHORNone

None[T]: Option[T]

Represents non-existent values of type T

ANCHORSome

@liftable
Some[T](value: T): Option[T]

Represents existing values of type T

ANCHORisNone

@liftable
isNone[T](opt: Option[T]): Bool

Returns true if the given option is a None or false if it is a Some

ANCHORisSome

@liftable
isSome[T](opt: Option[T]): Bool

Returns true if the given option is a Some or false if it is a None

ANCHORgetSome

@liftable
getSome[T](opt: Option[T]): T

Get the value contained in a Some. If the given option is a None, a run-time error will occur

ANCHORgetSomeOrElse

@liftable
getSomeOrElse[T](opt: Option[T], value: T): T

Get the value contained in a Some. If the given option is a None, the default value value will be returned

ANCHORStreamFunctions

Built-in stream functions

ANCHORnil

nil[T]: Events[T]

Returns an empty stream without any event of type T

ANCHORdefault

default[T](stream: Events[T], value: T): Events[T]

Returns a stream which contains all the events of the given stream. If stream has no event at timestamp 0, then an additional event with value value is added at timestamp 0.

Usage example:

in a: Events[Int]
def d = default(a, 42)
out d

Trace example:

option timeDomain: [-0.1,6]
stream a: bubbles
stream d: bubbles
---
0: d = 42
2: a = 17
2: d = 17
5: a = 23
5: d = 23

Alternative trace example:

option timeDomain: [-0.1,6]
stream a: bubbles
stream d: bubbles
---
0: a = 12
0: d = 12
2: a = 17
2: d = 17
5: a = 23
5: d = 23

ANCHORdefaultFrom

defaultFrom[T](valueStream: Events[T], defaultStream: Events[T]): Events[T]

Similar to default, this operation returns a stream which contains all the events of the given valueStream. If the first event on defaultStream happens strictly before the first event on valueStream then this event is added. No events other than the first event on defaultStream are considered.

Usage example:

in v: Events[Int]
in x: Events[Int]
def d = defaultFrom(v, x)
out d

Trace example:

stream v: bubbles
stream x: bubbles
stream d: bubbles
---
2: x = 5
2: d = 5
3: x = 3
3: d = 2
3: v = 2
5: x = 7
6: d = 4
6: v = 4

Alternative trace example:

stream v: bubbles
stream x: bubbles
stream d: bubbles
---
1: d = 6
1: v = 6
2: x = 5
3: x = 3
3: d = 2
3: v = 2
5: x = 7
6: d = 4
6: v = 4

ANCHORlift1

lift1[T, U](stream: Events[T], f: ((Option[T]) => Option[U]): Events[U]

Lifts a unary function f which is defined on values to a function on a stream and applies it to the given stream. The function f is called for every event on the streams. Because there is no other stream, the argument of f will never be None. (f is never called with all arguments being None.)

Usage example:

in a: Events[Int]
def f(a: Option[Int]) =
  if getSome(a) > 5 then a else None[Int]
def b = lift1(a,f)
out b

Trace example:

stream a: bubbles
stream b: bubbles
---
1: b = 7
1: a = 7
2: a = 5
4: a = 3
5: b = 9
5: a = 9

ANCHORlift2

lift2[T, U, V](stream1: Events[T], stream2: Events[U], f: ((Option[T], Option[U]) => Option[V]): Events[V]

Lifts a function f which is defined on values to a function on streams and applies it to the given streams. The function f is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to f. Otherwise the other argument is None if there is no simultaneous event on the other stream. f is never called with all arguments being None.

Usage example:

in a: Events[Int]
in b: Events[Int]
def f(a: Option[Int], b: Option[Int]) =
  if isSome(a) && getSome(a) > 5 then a else b
def c = lift(a,b,f)
out c

Trace example:

stream a: bubbles
stream b: bubbles
stream c: bubbles
---
1: c = 7
1: a = 7
2: a = 5
3: b = 6
3: c = 6
4: b = 2
4: c = 2
4: a = 3
5: b = 4
5: c = 9
5: a = 9

ANCHORlift

lift

ANCHORlift3

lift3[T1, T2, T3, T4](stream1: Events[T1], stream2: Events[T2], stream3: Events[T3], f: ((Option[T1], Option[T2], Option[T3]) => Option[T4]): Events[T4]

Lifts a function f which is defined on values to a function on streams and applies it to the given streams. The function f is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to f. Otherwise the other argument is None if there is no simultaneous event on the other stream. f is never called with all arguments being None.

Usage example:

in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
def f(a: Option[Int], b: Option[Int], c: Option[Int]) =
  if isSome(a) && getSome(a) > 5 then a
  else if isSome(b) then b else c
def d = lift3(a,b,c,f)
out d

Trace example:

stream a: bubbles
stream b: bubbles
stream c: bubbles
stream d: bubbles
---
1: d = 7
1: a = 7
2: a = 5
3: b = 6
3: d = 6
4: b = 2
4: d = 2
4: a = 3
5: c = 1
5: d = 1
6: b = 4
6: c = 3
6: d = 9
6: a = 9

ANCHORlift4

lift4[T1, T2, T3, T4, T5](stream1: Events[T1], stream2: Events[T2], stream3: Events[T3], stream4: Events[T4], f: ((Option[T1], Option[T2], Option[T3], Option[T4]) => Option[T5]): Events[T5]

Lifts a function f which is defined on values to a function on streams and applies it to the given streams. The function f is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to f. Otherwise the other argument is None if there is no simultaneous event on the other stream. f is never called with all arguments being None.

Usage example:

in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
in d: Events[Int]
def f(a: Option[Int], b: Option[Int], c: Option[Int], d: Option[Int]) =
  if isSome(a) && getSome(a) > 5 then a
  else if isSome(b) then b
  else if isSome(c) then c
  else d
def e = lift4(a,b,c,d,f)
out e

Trace example:

stream a: bubbles
stream b: bubbles
stream c: bubbles
stream d: bubbles
stream e: bubbles
---
1: a = 7
1: e = 7
2: a = 5
3: b = 6
3: e = 6
4: b = 2
4: a = 3
4: e = 2
5: e = 1
5: c = 1
6: d = 2
6: e = 2
7: b = 4
7: a = 9
7: d = 2
7: e = 9
7: c = 3

ANCHORlift5

lift5[T1, T2, T3, T4, T5, U](stream1: Events[T1], stream2: Events[T2], stream3: Events[T3], stream4: Events[T4], stream5: Events[T5], f: ((Option[T1], Option[T2], Option[T3], Option[T4], Option[T5]) => Option[U]): Events[U]

Lifts a function f which is defined on values to a function on streams and applies it to the given streams. The function f is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to f. Otherwise the other argument is None if there is no simultaneous event on the other stream. f is never called with all arguments being None.

See lift4 for a usage example. ~~~

ANCHORlast

last[T, U](stream: Events[T], trigger: Events[U]): Events[T]

The last operator takes two streams and returns the previous value of the first stream at the timestamps of the second. Note that while TeSSLa is defined on event streams, last realizes some essential aspects of the signal semantics: With this operator one can query the last known value of an event stream at a specific time and hence interpret the events on this stream as points where a piece-wise constant signal changes its value.

Usage example:

in values: Events[Int]
in trigger: Events[Unit]
def result = last(x,y)
out result

Trace example:

stream values: bubbles
stream trigger: unit events
stream result: bubbles
---
1: trigger = ()
2: values = 5
3: result = 5
3: trigger = ()
4: result = 5
4: trigger = ()
4: values = 3
5: result = 3
5: trigger = ()

prev

prev[A](a: Events[A]): Events[A]

Return the previous event of a. Does not work in recursive equations. Use last with an explicit external trigger in recursive equations instead.

Usage example:

in x: Events[Int]
def y = prev(x)
out y

Trace example:

option axis: true
stream x: bubbles
stream y: bubbles
---
1: x = 3
3: y = 3
3: x = 2
7: y = 2
7: x = 1
8: y = 1
8: x = 5

ANCHORtime

time[T](stream: Events[T]): Events[Int]

The time operator returns the stream of the timestamps of another stream

Usage example:

in x: Events[Int]
def y = time(x)
out result

Trace example:

option axis: true
option timeDomain: [0,14]
stream x: bubbles
stream y: bubbles
---
2: x = 5
2: y = 2
4: x = 3
4: y = 4
10: x = 42
10: y = 10

ANCHORdelay

delay[T](delays: Events[Int], resets: Events[T]): Events[Unit]

The delay operator takes delays as its first argument. After a delay has passed, a unit event is emitted. A delay can only be set if a reset event is received via the second argument, or if an event is emitted on the output.

Usage example:

in values: Events[Int]
in resets: Events[Int]
def result = delay(values, resets)
out result

Trace example:

option axis: true
stream values: bubbles
stream resets: unit events
stream result: unit events
---
1: resets = ()
1: values = 2
3: result = ()
4: resets = ()
4: values = 3
7: result = ()
7: values = 2
9: result = ()
9: resets = ()
9: values = 2
11: result = ()
11: values = 4
13: resets = ()

ANCHORconst

const[T, U](value: T, stream: Events[U]): Events[T]

Maps the event's values of a stream to given constant value.

Usage example:

in x: Events[Int]
def y = const(42, x)
out y

Trace example:

stream x: bubbles
stream y: bubbles
---
1: y = 42
1: x = 17
6: y = 42
6: x = 1
8: y = 42
8: x = 42
12: y = 42
12: x = 23

ANCHORfirst

first[T, U](stream1: Events[T], stream2: Events[U]): Events[T]

Returns a variant of stream1 which has every original events of stream1 and additional events with the last value of stream1 for every event of stream2. first is defined as the signal lift of the function f(a,b) = a.

Note, the difference between first(stream1, stream2) and merge(stream1, last(stream1, stream2)). Since first is defined via signal lift, it does not produce events before both input streams have been defined.

Usage example:

in x: Events[Int]
in y: Events[Int]
def z = first(x, y)
out z

Trace example:

stream x: signal
stream y: signal
stream z: signal
---
1: x = 17
2: y = 23
2: z = 17
3: z = 1
3: x = 1
4: y = 3
4: z = 1
6: y = 34
6: z = 42
6: x = 42
8: y = 12
8: z = 42

ANCHORslift1

slift1[T, U](stream: Events[T], f: ((T) => U): Events[U]

The unary signal lift is very similar to lift1. Since the lifted function is unary, there is no other stream with which events are being synchronized. The only difference is that slift1 takes a total function which cannot remove events.

Usage example:

in a: Events[Int]
def b = slift1(a, (x: Int) => x + 1)
out b

Trace example:

stream a: signal
stream b: signal
---
1: b = 3
1: a = 2
3: b = 6
3: a = 5
7: b = 4
7: a = 3

ANCHORslift2

slift2[T, U, V](a: Events[T], b: Events[U], f: ((T, U) => V): Events[V]

Takes a function f on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. f is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then f is called with the last known value of that stream. f is not called before every stream had at least one event.

Note, that in comparison to lift f takes no Option type. slift cannot filter events. The generated event pattern is independent of the lifted function f.

Usage example:

in a: Events[Int]
in b: Events[Int]
def z = slift(a, b, (v1: Int, v2: Int) => (v1 + v2) / 2)
out z

Trace example:

stream a: signal
stream b: signal
stream z: signal
---
2: a = 2
3: a = 3
5: b = 1
5: z = 2
7: b = 4
7: a = 5
7: z = 4
10: b = 7
10: z = 6
12: a = 6
12: z = 6

ANCHORslift

slift

ANCHORslift3

slift3[T1, T2, T3, T4](a: Events[T1], b: Events[T2], c: Events[T3], f: ((T1, T2, T3) => T4): Events[T4]

Takes a function f on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. f is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then f is called with the last known value of that stream. f is not called before every stream had at least one event.

Note, that in comparison to lift3 f takes no Option type. slift3 cannot filter events. The generated event pattern is independent of the lifted function f.

Usage example:

in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
def z = slift3(a, b, c, (v1: Int, v2: Int, v3: Int) => (v1 + v2 + v3) / 3)
out z

Trace example:

stream a: signal
stream b: signal
stream c: signal
stream z: signal
---
2: a = 2
3: a = 3
5: b = 1
6: c = 8
6: z = 4
7: b = 4
7: a = 5
7: z = 5
10: b = 7
10: z = 6
12: b = 9
12: c = 10
12: a = 6
12: z = 8

ANCHORslift4

slift4[T1, T2, T3, T4, T5](s1: Events[T1], s2: Events[T2], s3: Events[T3], s4: Events[T4], f: ((T1, T2, T3, T4) => T5): Events[T5]

Takes a function f on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. f is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then f is called with the last known value of that stream. f is not called before every stream had at least one event.

Note, that in comparison to lift4 f takes no Option type. slift4 cannot filter events. The generated event pattern is independent of the lifted function f.

Usage example:

in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
in d: Events[Int]
def z = slift4(a, b, c, d,
  (v1: Int, v2: Int, v3: Int, v4: Int) => (v1 + v2 + v3 + v4) / 4)
out z

Trace example:

stream a: signal
stream b: signal
stream c: signal
stream d: signal
stream z: signal
---
1: d = 12
2: a = 2
3: a = 3
5: b = 1
6: z = 6
6: c = 8
7: a = 5
7: b = 4
7: z = 7
10: b = 7
10: z = 8
12: a = 6
12: d = 11
12: b = 9
12: z = 9
12: c = 10

ANCHORslift5

slift5[T1, T2, T3, T4, T5, U](s1: Events[T1], s2: Events[T2], s3: Events[T3], s4: Events[T4], s5: Events[T5], f: ((T1, T2, T3, T4, T5) => U): Events[U]

Takes a function f on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. f is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then f is called with the last known value of that stream. f is not called before every stream had at least one event.

Note, that in comparison to lift5 f takes no Option type. slift5 cannot filter events. The generated event pattern is independent of the lifted function f.

See slift4 for a usage example.

ANCHORmerge2

merge2[T](stream1: Events[T], stream2: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

Usage example:

in a: Events[Int]
in b: Events[Int]
def z = merge(a,b)
out z

Trace example:

stream a: bubbles
stream b: bubbles
stream z: bubbles
---
1: a = 3
1: z = 3
2: b = 4
2: z = 4
3: a = 2
3: z = 2
7: b = 6
7: a = 1
7: z = 1
8: a = 5
8: z = 5

ANCHORmerge

merge

ANCHORmerge3

merge3[T](a: Events[T], b: Events[T], c: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See merge for a usage example.

ANCHORmerge4

merge4[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See merge for a usage example.

ANCHORmerge5

merge5[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See merge for a usage example.

ANCHORmerge6

merge6[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T], f: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See merge for a usage example.

ANCHORmerge7

merge7[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T], f: Events[T], g: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See merge for a usage example.

ANCHORmerge8

merge8[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T], f: Events[T], g: Events[T], h: Events[T]): Events[T]

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See merge for a usage example.

ANCHORmergeUnit2

mergeUnit2[T, U](a: Events[T], b: Events[U]): Events[Unit]

Merges streams of different types, resulting in a stream that contains a unit event whenever any of the input streams produces an event.

Usage example:

in x: Events[Int]
in y: Events[Bool]
def z = mergeUnit(x, y)
out z

Trace example:

stream x: bubbles
stream y: bubbles
stream z: unit events
---
1: x = 3
1: z = ()
2: y = false
2: z = ()
3: x = 2
3: z = ()
7: y = true
7: x = 1
7: z = ()
8: x = 5
8: z = ()

ANCHORmergeUnit

mergeUnit

ANCHORmergeUnit3

mergeUnit3[T, U, V](a: Events[T], b: Events[U], c: Events[V]): Events[Unit]

Merges streams of different types, resulting in a stream that contains a unit event whenever any of the input streams produces an event.

See mergeUnit for a usage example.

ANCHORmergeUnit4

mergeUnit4[T, U, V, W](a: Events[T], b: Events[U], c: Events[V], d: Events[W]): Events[Unit]

Merges streams of different types, resulting in a stream that contains a unit event whenever any of the input streams produces an event.

See mergeUnit for a usage example.

ANCHORfilter

filter[A](events: Events[A], condition: Events[Bool]): Events[A]

Filter the event stream events based on the last known value of the boolean signal condition.

Usage example:

in x: Events[String]
in c: Events[Bool]
def y = filter(x, c)
out y
stream x: events
stream c: signal
stream y: events
---
1: x = "Hello"
2: c = true
3: x = "World"
3: y = "World"
7: c = false
7: x = "Hey"
8: x = "You"

ANCHORpure

pure[T](x: Events[T]): Events[T]

Removes subsequent events with the same value

Usage example:

in x: Events[Int]
def y = pure(x)
out y

Trace example:

stream x: signal
stream y: signal
---
2: y = 3
2: x = 3
4: x = 3
5: x = 3
6: y = 1
6: x = 1
8: y = 2
8: x = 2
10: x = 2
12: y = 4
12: x = 4

ANCHORisFirst

isFirst[A](x: Events[A]): Events[Bool]

Signal which is only true with first event on x

Usage example:

in x: Events[Int]
def f = isFirst(x)
out f

Trace example:

stream x: bubbles
stream f: signal
---
0: f = false
2: f = true
2: x = 3
6: f = false
6: x = 1
8: f = false
8: x = 2
12: f = false
12: x = 4

ANCHORfirstEvent

firstEvent[A](x: Events[A]): Events[A]

Filters x such that only the first event on x remains

Usage example:

in x: Events[Int]
def y = firstEvent(x)
out y

Trace example:

stream x: bubbles
stream y: bubbles
---
2: y = 3
2: x = 3
6: x = 1
8: x = 2
12: x = 4

ANCHORdefined

defined[T](x: Events[T]): Events[Bool]

Signal, which becomes true with the first event on x

Usage example:

in x: Events[Int]
def f = defined(x)
out f

Trace example:

stream x: bubbles
stream f: signal
---
0: f = false
2: f = true
2: x = 3
6: f = true
6: x = 1
8: f = true
8: x = 2
12: f = true
12: x = 4

ANCHORruntime

runtime[A, B](call: Events[A], ret: Events[B]): Events[Int]

Compute the runtime of a function on every ret event. The runtime is the time passed between the last call event and the ret event. The values of the events are ignored.

Usage example:

in call: Events[Unit]
in ret: Events[Unit]
def rt = runtime(call, ret)
out rt

Trace example:

option axis: true
option timeDomain: [5,75]
stream call: unit events
stream ret: unit events
stream rt: events
---
10: call = ()
17: ret = ()
17: rt = 7
25: call = ()
35: ret = ()
35: rt = 10
57: call = ()
69: ret = ()
69: rt = 12

ANCHORmaximum

maximum(x: Events[Int]): Events[Int]

Compute the maximum value of all events on x. Provides for every input event and output event whose value is the maximum up to this point.

Usage example:

in x: Events[Int]
def m = maximum(x)
out m

Trace example:

stream x: bubbles
stream m: signal
---
2: m = 4
2: x = 4
6: m = 4
6: x = 2
8: m = 5
8: x = 5
12: m = 5
12: x = 3

ANCHORminimum

minimum(x: Events[Int]): Events[Int]

Compute the minimum value of all events on x. Provides for every input event and output event whose value is the minimum up to this point.

Usage example:

in x: Events[Int]
def m = minimum(x)
out m

Trace example:

stream x: bubbles
stream m: signal
---
2: m = 4
2: x = 4
6: m = 2
6: x = 2
8: m = 2
8: x = 5
12: m = 2
12: x = 3

ANCHORcount

count[T](x: Events[T]): Events[Int]

Count the number of events on x. Provides for every input event an output event whose value is the number of events seen so far. See resetCount for a counting macro with an external reset.

Usage example:

in x: Events[Unit]
def y = count(x)
out y

Trace example:

stream x: unit events
stream y: signal
---
0: y = 0
2: y = 1
2: x = ()
6: y = 2
6: x = ()
7: y = 3
7: x = ()
9: y = 4
9: x = ()

ANCHORsum

sum(x: Events[Int]): Events[Int]

Sum up the values of all events on x. Provides for every input event an output event whose value is the sum of the values of all events seen so far.

Usage example:

in x: Events[Int]
def y = sum(x)
out y

Trace example:

stream x: bubbles
stream y: signal
---
0: y = 0
2: y = 2
2: x = 2
6: y = 10
6: x = 8
7: y = 13
7: x = 3
9: y = 14
9: x = 1

ANCHORfold

fold[T, R](stream: Events[T], init: R, f: ((R, T) => R): Events[R]

Fold a function on values over all events on stream. Starting with the initial value init the function f is called for every event on stream with the last result and the current event’s value as arguments. So for the input stream x

2: x = 2
4: x = 6
5: x = 1

the call def y = fold(f, x, 0) produces the following stream y:

0: y = 0
2: y = f(0,2)
4: y = f(f(0,2),6)
5: y = f(f(f(0,2),6),1)

See count for an example of fold in action. count is defined as fold(x, 0, inc).

ANCHORreduce

reduce[T](stream: Events[T], f: ((Events[T], Events[T]) => Events[T]): Events[T]

Fold a function on values over all events on stream. Starting with the first event on stream as initial value, the function f is called for every later event on stream with the last result and the current event’s value as arguments. So for the input stream x

2: x = 2
4: x = 6
5: x = 1

the call def y = reduce(f, x) produces the following stream y:

2: y = 2
4: y = f(2,6)
5: y = f(f(2,6),1)

See minimum for an example of reduce in action. minimum is defined as reduce(x, min).

ANCHORresetCount

resetCount[A, B](events: Events[A], reset: Events[B]): Events[Int]

Count the number of events on events. Reset the output to 0 on every event on reset.

Usage example:

in events: Events[Unit]
in resets: Events[Unit]
def result = resetCount(events, resets)
out result

Trace example:

stream events: unit events
stream resets: unit events
stream result: signal
---
0: result = 0
2: events = ()
2: result = 1
3: events = ()
3: result = 2
5: events = ()
5: result = 3
7: resets = ()
7: events = ()
7: result = 1
9: events = ()
9: result = 2
10: events = ()
10: result = 3
12: resets = ()
12: result = 0
14: events = ()
14: result = 1
15: events = ()
15: result = 2

ANCHORbursts

bursts[A](e: Events[A], burstLength: Int, waitingPeriod: Int, burstAmount: Int): Events[Bool]

Check if events on e follow the burst pattern: After first event on e only burstAmount many events allowed during burstLength time. After burstLength during waitingPeriod time no event allowed. After waitingPeriod we wait for the next event on e.

in send: Events[Unit]
def property :=
  bursts(send, burstLength = 3s,
    waitingPeriod = 2s, burstAmount = 4)
out property
option axis: true
option timeDomain: [0, 9000000000]
stream send: unit events
stream property: signal
---
0: property = true
500191958: property = true
500191958: send = ()
1000275162: property = true
1000275162: send = ()
1500422455: property = true
1500422455: send = ()
2000525066: property = true
2000525066: send = ()
4500724637: property = false
4500724637: send = ()
5000822890: property = false
5000822890: send = ()
7501025420: property = true
7501025420: send = ()
8001141937: property = true
8001141937: send = ()
8501245567: property = true
8501245567: send = ()

ANCHORburstsSince

burstsSince[A, B](e: Events[A], burstLength: Int, waitingPeriod: Int, burstAmount: Int, since: Events[B]): Events[Bool]

Check if events on e follow the burst pattern since the last event on since: After first event on e only burstAmount many events allowed during burstLength time. After burstLength during waitingPeriod time no event allowed. After waitingPeriod we wait for the next event on e.

Usage example:

in reset: Events[Unit]
in e: Events[Unit]
def p := burstsSince(e, burstLength = 2s,
                        waitingPeriod = 1s,
                        burstAmount = 3,
                        since = reset)
out p
option axis: true
option timeDomain: [0, 17000]
stream e: unit events
stream reset: unit events
stream p: signal
---
0: p = true
3000: e = ()
3000: p = true
3500: e = ()
3500: p = true
4000: e = ()
4000: p = true
4500: e = ()
4500: p = false
6000: reset = ()
7000: e = ()
7000: p = true
8000: e = ()
8000: p = true
12000: e = ()
12000: p = true
14500: e = ()
14500: p = false
16000: e = ()
16000: p = true

ANCHORnoEvent

noEvent[A, B](on: Events[A], since: Events[B]): Events[Bool]

Check if no event happened on on after last event on since.

Usage example:

in reset: Events[Unit]
in e: Events[Unit]
def p := noEvent(e, since = reset)
out p

Trace example:

option timeDomain: [0,16]
stream e: unit events
stream reset: unit events
stream p: signal
---
0: p = true
2: e = ()
2: p = false
4: e = ()
4: p = false
6: reset = ()
6: p = true
12: e = ()
12: p = false

ANCHORconstIf

constIf[T](value: T, condition: Events[Bool]): Events[T]

Produce an event with the given value every time that the condition is met

Usage example:

in condition: Events[Bool]
def result = constIf(42, condition)
out result

Trace example:

2: condition = false
4: result = 42
4: condition = true
5: result = 42
5: condition = true
8: condition = false
9: condition = false
10: condition = false
12: result = 42
12: condition = true

ANCHORunitIf

unitIf(cond: Events[Bool]): Events[Unit]

Produces a unit event every time the condition is fulfilled

Usage example:

in condition: Events[Bool]
def result = unitIf(condition)
out result

Trace example:

2: condition = false
4: result = ()
4: condition = true
5: result = ()
5: condition = true
8: condition = false
9: condition = false
10: condition = false
12: result = ()
12: condition = true

ANCHORrising

rising(condition: Events[Bool]): Events[Unit]

Detect rising edge on condition

Usage example:

in condition: Events[Bool]
def result = rising(condition)
out result

Trace example:

stream condition: plot
stream result: unit events
---
2: condition = false
4: result = ()
4: condition = true
5: condition = true
8: condition = false
9: condition = false
10: condition = false
12: result = ()
12: condition = true

ANCHORfalling

falling(condition: Events[Bool]): Events[Unit]

Detect falling edge on condition

Usage example:

in condition: Events[Bool]
def result = falling(condition)
out result

Trace example:

stream condition: plot
stream result: unit events
---
2: condition = false
4: condition = true
5: condition = true
8: result = ()
8: condition = false
9: condition = false
10: condition = false
12: condition = true

ANCHORon

on[A, B](trigger: Events[A], stream: Events[B]): Events[B]

Produce the current or last value on stream for every trigger

Usage example:

in trigger: Events[Unit]
in stream: Events[Int]
def result = on(trigger, stream)
out result

Trace example:

stream stream: signal
stream trigger: unit events
stream result: signal
---
2: trigger = ()
3: stream = 3
5: trigger = ()
5: result = 3
7: stream = 2
8: stream = 1
10: trigger = ()
10: result = 1
12: stream = 4
12: trigger = ()
12: result = 4
14: trigger = ()
14: result = 4

ANCHORaverage

average(x: Events[Int]): Events[Int]

Compute the average value of all events on x. For every input event on x an output event is produced whose value is the average of all values seen so far.

Usage example:

in stream: Events[Int]
def result = average(stream)
out result

Trace example:

stream stream: bubbles
stream result: bubbles
---
3: result = 3
3: stream = 3
7: result = 2
7: stream = 2
8: result = 2
8: stream = 1
12: result = 2
12: stream = 4

ANCHORperiod

period(freq: Int): Events[Unit]

Produce an event stream with a unit event every delay time units. Starting with an event at timestamp 0.

Usage example:

in progress: Events[Unit]
def output = period(3)
out output
option axis: true
stream progress: unit events
stream output: unit events
---
0: output = ()
3: output = ()
6: output = ()
9: output = ()
12: output = ()
15: output = ()
18: output = ()
20: progress = ()

ANCHORsample

sample[A](e: Events[A], rate: Int): Events[A]

Filter out events to ensure a maximal event rate. Forwards the first event on e and afterwards every event which is at least rate time units later then the last forwarded event.

Usage example:

in x: Events[Int]
def y = sample(x, 5)
out y

Trace example:

option axis: true
stream x: events
stream y: events
---
2: y = 5
2: x = 5
4: x = 3
5: x = 4
7: y = 2
7: x = 2
9: x = 1
10: x = 8
13: y = 3
13: x = 3
15: x = 9
16: x = 7
18: y = 6
18: x = 6
20: x = 2
23: y = 4
23: x = 4
25: x = 9

ANCHORList

Lists

ANCHORList.empty

empty[T]: List[T]

ANCHORList.size

@liftable
size[T](list: List[T]): Int

ANCHORList.isEmpty

@liftable
isEmpty[T](list: List[T]): Bool

ANCHORList.append

@liftable
append[T](list: List[T], element: T): List[T]

ANCHORList.prepend

@liftable
prepend[T](element: T, list: List[T]): List[T]

ANCHORList.tail

@liftable
tail[T](list: List[T]): List[T]

ANCHORList.init

@liftable
init[T](list: List[T]): List[T]

ANCHORList.get

@liftable
get[T](list: List[T], index: Int): T

ANCHORList.set

@liftable
set[T](list: List[T], index: Int, value: T): List[T]

ANCHORList.head

@liftable
head[T](list: List[T]): T

ANCHORList.last

@liftable
last[T](list: List[T]): T

ANCHORList.fold

@liftable
fold[T, U](list: List[T], start: U, f: ((U, T) => U): U

ANCHORType List

List[T]

ANCHORSet

Set

ANCHORSet.empty

empty[T]: Set[T]

ANCHORSet.singleton

@liftable
singleton[T](value: T): Set[T]

ANCHORSet.add

@liftable
add[T](set: Set[T], item: T): Set[T]

ANCHORSet.contains

@liftable
contains[T](set: Set[T], item: T): Bool

ANCHORSet.remove

@liftable
remove[T](set: Set[T], item: T): Set[T]

ANCHORSet.size

@liftable
size[T](set: Set[T]): Int

ANCHORSet.union

@liftable
union[T](set1: Set[T], set2: Set[T]): Set[T]

ANCHORSet.intersection

@liftable
intersection[T](set1: Set[T], set2: Set[T]): Set[T]

ANCHORSet.minus

@liftable
minus[T](set1: Set[T], set2: Set[T]): Set[T]

ANCHORSet.fold

@liftable
fold[T, U](set: Set[T], start: U, f: ((U, T) => U): U

ANCHORSet.collect

collect[T](value: Events[T])

ANCHORSet.set

set: Events[Set[T]]

ANCHORSet.collectWithRemove

collectWithRemove[T](value: Events[T], removeValue: Events[T])

ANCHORSet.old

old

ANCHORSet.operation

operation: Events[Set[T]]

ANCHORSet.set

set

ANCHORType Set

Set[T]

ANCHORMap

Maps

ANCHORMap.empty

empty[K, V]: Map[K, V]

ANCHORMap.add

@liftable
add[K, V](map: Map[K, V], key: K, value: V): Map[K, V]

ANCHORMap.contains

@liftable
contains[K, V](map: Map[K, V], key: K): Bool

ANCHORMap.get

@liftable
get[K, V](map: Map[K, V], key: K): V

ANCHORMap.remove

@liftable
remove[K, V](map: Map[K, V], key: K): Map[K, V]

ANCHORMap.size

@liftable
size[K, V](map: Map[K, V]): Int

ANCHORMap.keys

@liftable
keys[K, V](map: Map[K, V]): List[K]

ANCHORMap.fold

@liftable
fold[K, V, R](map: Map[K, V], start: R, f: ((R, K, V) => R): R

ANCHORMap.getOrElse

@liftable
getOrElse[K, V](map: Map[K, V], key: K, default: V): V

ANCHORMap.inc

@liftable
inc[K](counts: Map[K, Int], key: K): Map[K, Int]

ANCHORMap.collectCount

collectCount[T](events: Events[T]): Events[Map[T, Int]]

ANCHORMap.collectMax

collectMax[K](key: Events[K], value: Events[Int]): Events[Map[K, Int]]

ANCHORMap.oldMap

oldMap

ANCHORMap.maxValue

maxValue: Events[Int]

ANCHORMap.map

map: Events[Map[K, Int]]

ANCHORMap.collectMin

collectMin[A](key: Events[A], value: Events[Int])

ANCHORMap.oldMap

oldMap

ANCHORMap.minValue

minValue: Events[Int]

ANCHORMap.map

map: Events[Map[A, Int]]

ANCHORMap.counting

counting[A](x: Events[A])

Map every new key to a unique integer ID

ANCHORMap.counter

counter: Events[Int]

ANCHORMap.map

map: Events[Map[A, Int]]

ANCHORType Map

Map[K, V]

ANCHORString

Strings

ANCHORString.concat

@liftable
concat(str1: String, str2: String): String

ANCHORString.format

@liftable
format[T](formatString: String, value: T): String

ANCHORString.formatInt

@liftable
formatInt(formatString: String, value: Int): String

ANCHORString.formatFloat

@liftable
formatFloat(formatString: String, value: Float): String

ANCHORMITL

MITL[S_{0,∞}]

ANCHORMITL.since0

since0(x: Int, a: Events[Bool], b: Events[Bool]): Events[Bool]

a S[0, x] b, x > 0

ANCHORMITL.sinceInfinity

sinceInfinity(x: Int, a: Events[Bool], b: Events[Bool]): Events[Bool]

a S[x, ∞] b, x ≥ 0

ANCHORMITL.firstA

firstA: Events[Bool]

ANCHORMITL.start

start

ANCHORMITL.once0

once0(x: Int, a: Events[Bool])

O[0, x] a

ANCHORMITL.onceInfinity

onceInfinity(x: Int, a: Events[Bool])

O[x, ∞] a

ANCHORMITL.historically0

historically0(x: Int, a: Events[Bool])

H[0, x] a

ANCHORMITL.historicallyInfinity

historicallyInfinity(x: Int, a: Events[Bool])

H[x, ∞] a

ANCHORLTL

past-time LTL

ANCHORLTL.since

since(a: Events[Bool], b: Events[Bool]): Events[Bool]

a S b

ANCHORLTL.once

once(a: Events[Bool]): Events[Bool]

O a

ANCHORLTL.historically

historically(a: Events[Bool]): Events[Bool]

H a

ANCHORInstrumentationAnnotations

Annotations controlling the instrumentation of C code

ANCHORAnnotation @InstFunctionCall

@InstFunctionCall(name: String)

Add event generation to every call of the function before the actual function call

ANCHORAnnotation @InstFunctionCallArg

@InstFunctionCallArg(name: String, index: Int)

Add event generation to every call of the function before the actual function call

ANCHORAnnotation @InstFunctionCalled

@InstFunctionCalled(name: String)

Add event generation to the first line of the function

ANCHORAnnotation @InstFunctionCalledArg

@InstFunctionCalledArg(name: String, index: Int)

Add event generation to the first line of the function

ANCHORAnnotation @InstFunctionReturn

@InstFunctionReturn(name: String)

Add event generation to every return inside of the function. Generates unit events.

ANCHORAnnotation @InstFunctionReturnValue

@InstFunctionReturnValue(name: String)

Add event generation to every return inside of the function. Generates events carrying the returned value as data.

ANCHORAnnotation @InstFunctionReturned

@InstFunctionReturned(name: String)

Add event generation to every call of the function after the function returned. Generates unit events.

ANCHORAnnotation @InstFunctionReturnedValue

@InstFunctionReturnedValue(name: String)

Add event generation to every call of the function after the function returned. Generates events carrying the returned value as data.

ANCHORAnnotation @GlobalRead

@GlobalRead(lvalue: String)

Instrument every reading access of a global variable with the given name. Can handle more complex patterns, e.g. *&bar[][].foo

ANCHORAnnotation @GlobalReadIndex

@GlobalReadIndex(lvalue: String)

Instrument every reading access of a global variable with the given name. Can handle more complex patterns, e.g. *&bar[][].foo Get the index as event's value.

ANCHORAnnotation @LocalRead

@LocalRead(lvalue: String, function: String)

Instrument every reading access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. *&bar[][].foo

ANCHORAnnotation @LocalReadIndex

@LocalReadIndex(lvalue: String, function: String)

Instrument every reading access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. *&bar[][].foo Get the index as event's value.

ANCHORAnnotation @GlobalWrite

@GlobalWrite(lvalue: String)

Instrument every writing access of a global variable with the given name. Can handle more complex patterns, e.g. *&bar[][].foo

ANCHORAnnotation @GlobalWriteIndex

@GlobalWriteIndex(lvalue: String)

Instrument every writing access of a global variable with the given name. Can handle more complex patterns, e.g. *&bar[][].foo Get the index as event's value.

ANCHORAnnotation @LocalWrite

@LocalWrite(lvalue: String, function: String)

Instrument every writing access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. *&bar[][].foo

ANCHORAnnotation @LocalWriteIndex

@LocalWriteIndex(lvalue: String, function: String)

Instrument every writing access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. *&bar[][].foo Get the index as event's value.

ANCHORAnnotation @ThreadId

@ThreadId

Writes the current thread ID to the annotated stream every time any other instrumentation produces any event

ANCHORTessla

The Tessla module contains meta data about the used Tessla compiler and interpreter or engine.

ANCHORTessla.version

version: String

The current TeSSLa version

ANCHORCTF

Common Trace Format

ANCHORType CTF.Object

Object

ANCHORCTF.getInt

@liftable
getInt(ctfObject: Object, member: String): Int

ANCHORCTF.getString

@liftable
getString(ctfObject: Object, member: String): String