151
CLEM Language Reference
Sequence functions
Record indexing
Averaging, summing, and comparing values
Monitoring change—differentiation
@SINCE
Offset values
Additional sequence facilities
For many applications, each record passing through a stream can be consid ered as an individual
case, independent of all others. In such situations, the o rder of records is usually unimportant.
For some classes of problems, however, the record sequence is very important. These are
typically time series situations, in which the sequence of records represents an orde red sequence
of events or occurrences. Each record represents a snapshot a ta pa rticular instant in time; much
of the richest information, however, might be contained not in instantaneous values but in t he
way in which such values are changing and behaving over time.
Of course, the relevant parameter may be something other than time. Forexa mple, the records
could represent analyses performed at distances along a line, but the same principles would apply.
Sequence and special functions are immediately recognizable by the foll owing characteristics:
They are all prexed by @.
Their names are given in upper case.
Sequence functions can refer to the record currently being processed by a node, the records that
have already passed through a node, and even, in one case, records that have yet to pass through
a node. Sequence functions can be mixed freely with other comp onents of CLEM expressions,
although some have restrictions on what can be used as their arguments.
Examples
Youmay nd it useful to know how long it has b een since a certain event occurred or a condition
was true. Use the function @SINCE to do this—for exam ple:
@SINCE(Income> Outgoings)
This function returns the offset of the last record where this condition was true—that is, the
number of records before this one in which the condition was true. If t he condition has never been
true, @SINCE returns @INDEX + 1.
Sometimes you may want to refer to a value of the current record in the expression used by
@SINCE. Youcan do this using the fun ction @THIS, which species that a eld name always
applies to the current record. To nd the offset of the last record that had a Concentration eld
value more than twice that of the current record, you could use:
@SINCE(Concentration> 2 * @THIS(Concentration))
In some cases the condition given to @SINCE is true of the current record by denition—for
example:
@SINCE(ID== @THIS(ID))