Language

Introduction

EScala is an extension of the Scala programming language which supports events as attributes of objects. In EScala, events can be defined declaratively by expressions combining other events, or imperatively as realized in C#.

This section gives an overview of the language features and how to use them.

Event Declaration

An event can be declared as member of a class using the evt keyword. An event can either be declared as imperative, i.e. occurrences are imperatively triggered in code (as in C#), or defined declaratively with an expression.

class Figure {
imperative evt changed[Unit]
}

In this example, the class Figure defines an imperative event named changed, which provides no data with its occurrences (Unit type). Occurrences of an imperative event can then be imperatively created in the code by calling the event as a method.

changed() // create an occurrence of the changed event

Another way to define an event is to declaratively define it with an expression. EScala provides a way to combine events together using different types of operators:

  • e || e' (event disjunction) The resulting event is triggered whenever e or e' occurs.
  • e && e' (event conjunction) The resulting event is triggered whenever e and e' occur simultaneously.
  • e && f (event filtering) The resulting event is triggered whenever e occurs and the given filter function f evaluates to true.
  • e.map(f) (parameter mapping) The resulting event is triggered whenever e occurs, and the parameter types and value are transformed by the function f passed to the map operator (We will explain it in more details below).

So we could define different events in the Figure class using these combinators

class Figure {
imperative evt resized[Unit]
imperative evt moved[Unit]
evt changed = resized || moved
}

The changed event in this example is defined as the disjunction of two other events named resized and moved. The type parameter declaration can be omitted in the definition of changed and will be inferred by the compiler.