In this page you can find some working snippets of EveXL. Just copy and paste them in the code editor at the end of the page
to try them out (or use the "Try this!" buttons to save some time). You can also edit the code as you please. Time to get creative!
P.S.: Don't forget to turn on the stream generator after writing the expressions in the editor!
Example 1 - Simply red
This expression will match a single reading of the "color" sensor as 'red'. Pretty simple! It should be read as:
- (1) I is an interval during which the "color" sensor reads the value 'red'
Example 2 - Simply red... only longer
This expression will match three succeeding readings of 'red'. It reads like:
- (1) I is an interval of 'red' readings
- (2) I lasts for 3 units of time
Example 3 - One interval, 3 colors
This expression will match an interval with duration 3, during which the "color" sensor reads values of 'red', 'green' or 'blue'.
- (1) I is an interval of 'red', 'green' or 'blue' readings
- (2) duration of I is 3
Example 4 - Two intervals
This expression will match two intervals with different color readings, regardless of the order they take place:
- (1) Red is an interval of 'red' readings
- (2) Green is an interval of 'green' readings
Example 5 - The meeting of two intervals
What if we wanted to detect when our sensor stops reading green and starts reading red?
- (1) Green is an interval of 'green' readings
- (2) Red is an interval of 'red' readings
- (3) interval Green is immediately followed (meets) by interval Red
Example 6 - Two intervals meet, second lasts longer
This is the same as the previous expression, but this time the second interval (red readings) lasts longer than the first (green
readings):
- (1) Green is an interval of 'green' readings
- (2) Red is an interval of 'red' readings
- (3) interval Green is immediately followed (meets) by interval Red
- (4) duration of interval Red is greater than that of interval Green
Example 7 - The meeting of three progressively longer intervals
This is the same as Example 6, though with three progressively longer intervals:
- (1) Green is an interval of 'green' readings
- (2) Red is an interval of 'red' readings
- (3) Blue is an interval of 'blue' readings
- (4) interval Green is immediately followed (meets) by interval Red, which is met by interval Blue
- (5) interval Green is shorter than Red, and Red is shorter than Blue
Example 8 - Covering ground
What if we were interested in detecting different situations? This event will succeed on either 1 reading of 'red', or 2 readings
of 'green' or 3 readings of 'blue'.
- (1) Red is an interval of 'red' readings
- (2) Green is an interval of 'green' readings
- (3) Blue is an interval of 'blue' readings
- (4-6) duration of Red is 1 or duration of Green is 2 or duration of Blue is 3
Example 9 - Timespan
We could, of course, be interested in events taking place temporally close to one another. Let's find when a single red and a
single blue ball fall with, at most, 2 readings in between.
- (1) Red is an interval of 'red' readings
- (2) Blue is an interval of 'blue' readings
- (3) T is an interval of time
- (4) T is started by Red and finished by Blue
- (5) duration of T ≤ 4 (i.e., we count the duration of both Red and Blue intervals plus a maximum of 2 other, neither
red nor blue readings in between).
Here's an alternative expression:
- (1) Red is an interval of 'red' readings
- (2) Blue is an interval of 'blue' readings
- (3) T is an interval of time
- (4) Red meets T and T meets Blue
- (5) duration of T ≤ 2 (i.e., this is the duration of time period between Red and Blue)
Example 10 - Blue, wait... bingo!
Let's trigger an event sometime after something else occurred. In this case, this event will trigger two readings after an
interval of blue balls has ended.
- (1) Blue is an interval of 'blue' readings
- (2) T is an interval time
- (3) the duration of T is 2
- (4) T is met by Blue
Partial Matching
Intervals of time can be divided in smaller intervals. After all, when you spend an interval of 2 hours watching TV, you have
also spent 2 intervals of 1 hour watching TV, 4 intervals of 30 minutes, and so on... EveXL makes possible to consider these
subintervals, by using the PARTIAL keyword after declaring an interval.
Example 11 - Single blue, wait... bingo!
For instance, the following event will trigger two readings after a blue ball is detected, even if the subsequent readings are
also of blue balls.
- (1) Blue is an interval of 'blue' readings, and can be part of a longer interval
- (2) T is an interval time
- (3) the duration of T is 2
- (4) T is met by Blue
Example 12 - Three green balls
The following event will trigger whenever three green balls are detected one after the other, even if they're
part of a longer interval of sequential green readings.
Time Juggling
The following examples just use time intervals. Since we are only interested in the passing of time, the generator will act as a
water clock: regardless of their color, each item drop counts as a time unit (clepsydra).
P.S.: Since in the following snippets we don't care about colors, it's always possible to write equivalent (and simpler)
expressions involving only a single interval of time with a fixed duration... but, hey - where's the fun in that?
Example 13 - Just time
- (1) T is an interval of time
- (2) T lasts 3 units of time
Example 14 - With age comes wisdom
You know that feeling that as we grow older time seems to just slip away faster? Well, here's an EveXL expression for that perception.
- (1-3) Childhood, Adulthood and OldAge are intervals of time
- (4-5) Childhood lasts longer than Adulthood which, in turn, lasts longer than OldAge
- (6) OldAge lasts one reading (otherwise it would be 0)
- (7) Childhood is followed by Adulthood which, in turn, is followed by OldAge
Example 15 - Twilight Zone
This expression is a temporal model of the morning twilight (i.e., light before sunrise).
For clarity, here's a visual model (CC 3.0):
The expression should be read as:
- (1-6) MorningTwilight, Night, AstronomicalTwilight, NauticalTwilight, CivilTwilight and Day are intervals of time (...well,
obviously)
- (8-11) Intervals Night, AstronomicalTwilight, NauticalTwilight, CivilTwilight and Day happen in sequence
- (13-14) MorningTwilight is started by AstronomicalTwilight and finished by CivilTwilight
- (16-17) Night has the same duration as Day (...let's keep it simple!) and Night is longer than AstronomicalTwilight
- (19-21) AstronomicalTwilight, NauticalTwilight and CivilTwilight have the same duration of 1 temporal unit
Try It!
The generator below will produce a random stream of readings (remember: use the colored buttons to create readings), so write
whatever expression you'd like to try or copy one of the above!