User's Manual

151
CLEM Language Reference
Sequence functions
Record indexing
Averaging, summing , and comparing value s
Monitoring change—differentiation
@SINCE
Offset values
Additi onal sequence facilities
For many applications, each record passing thro ugh a stream can be consider ed as an individual
case, independent of all others. In such situ ations, the order of records is usually unimportant.
For some classes of problems, however, the record seq uence is very important. These are
typically time series situations, in which the sequ ence of records represents an ordered seq uence
of events or occurrences. Each r ecord represents a snapshot at a p articular instant in time; much
of the richest information, however, might be contained not in instanta neous values but in the
way in which such values are changing and behaving over time.
Of c ourse, the relevant parameter may be som ething other than time. For example, the records
could represent analyses performed at distances alo ng a line, but the same principles would apply.
Sequence and special f unctions are immediate ly re cognizable by the following characteristics:
They are all prexed by @.
Their names are given in upper case.
Sequence function s 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 func tions can be mixed freely with other components of CLEM expres sions,
although some have restric tions on what can be used a s their arguments.
Examples
You may nd it useful to know how long it has be en since a certain event occurred or a con dition
was true. Use the function @SINCE to do this—fo r example:
@SINCE(Income > Outgoings)
This function returns the offset of the last record where this condition was true—that is, the
number of records be f ore t his one in which the condition was true. If the condition has never been
true, @SINCE returns @INDEX + 1.
Sometimes yo u may want to refer to a value of the current record in the e xpression used by
@SINCE. You can do this using the function @THIS, which species that a el d name always
applies to the current record. To nd the offset of the last record that had a Concentration eld
value more than tw ice that of the current record, you could u se:
@SINCE(Concentration > 2 * @THIS(Concentration))
In some cases the condition given to @SINCE is true of t he current record by denition—for
example:
@SINCE(ID == @THIS(ID))