Expressions
Planimate Expression Language
Planimate supports numerical expressions. These can be entered using the routine text editor or in an Attribute Reference Dialog which has been configured as "Expression". They enable more complex mathematical, logical and string operations to be expressed in an algebraic form rather than over multiple lines of routine code.
The following operators and types can be used in an expression. They are listed in order of precedence - the higher ones in the list will evaluate before the lower ones (BODMAS rules are followed).
number | Numeric constant |
reference | Attribute/cell/row/column/label reference, references data in a model |
"string" | Quoted text string |
'x' | Single ASCII character |
ref.prop | Property of a referenced datum |
[] | Index property for tables and lists |
function() | Internal expression function |
ref.func() | Property function of a referenced datum |
! | Logical NOT, !1=0, !123=0, !0=1 |
/ | Arithmetic divide |
% | Arithmetic modulus |
* | Arithmetic multiply |
+ | Arithmetic add |
- | Arithmetic subtract |
< | Logical less than |
<= | Logical less than or equal |
> | Logical greater than |
>= | Logical greater than or equal |
== | Logical equal (values follow PL's equality check rules) |
!= | Logical not equal |
^ | Logical exclusive-or 0^0=0, 0^1=1, 1^0=1, 1^1=0 |
&& | Logical AND |
|| | Logical OR |
& | String concatenate |
, | Comma separator for parameters to functions |
Brackets () can be used to force order, eg: (a + b) * c
Functions
As well as the operators above, a number of functions can be used. These can be nested and are particularly useful for complex math and string manipulation.
References
The most useful ability of expressions is the ability to reference multiple pieces of data in a Planimate model. Typically such a reference has a type letter, followed by a period then the datum's name.
Most operations expect numeric data. Some expect entire table rows, tables, columns, label lists or strings. In case where a string is needed, Planimate will automatically translate values to a string, following the format of the container of the value.
Example | Type | Context | comments | ||||
---|---|---|---|---|---|---|---|
i.attribute | Value | Item | Attribute defined for an item class but uniquely settable for each | ||||
p.attribute | Value / String | Subsystem | Attribute defined and only visible within a subsystem and the portal/subsystems contained therein. | ||||
r.attribute | Value / String | Routine (Change) | Attribute defined within a routine (or subroutine). String attributes are not recursive within subroutines that call themselves but values are. | ||||
s.attname | Value / String | System wide | System provided access to properties and settings of the runtime environment | ||||
t.tablename[rowindex][colindex] | Value / String | Subsystem | References a table cell. 'colindex' can be a column label for the table. | t.tablename | Table | Subsystem | Reference to an entire table |
t.tablename.Row(value) | Table Row | Subsystem | Reference to an entire table row | ||||
t.tablename.Column(value) | Table Row | Subsystem | Reference to an entire table column | ||||
t.tablename.MatchedRow(value) | Table Row | Subsystem | Reference to an entire table row determined by search for a 'key' in a 'column' | ||||
t.tablename.MatchedCell(keycol,col,key) | Value / String | Subsystem | Reference to a table cell determined by search for a 'key' in a 'keycol'. The cell is taken from column 'col'. | ||||
t.tablename.MatchedIndex(keycol,key) | Value | Subsystem | The row number determined by search for a 'key' in a 'keycol' | ||||
t.tablename.Remap(x,ycol) | Value | Subsystem | Lookup and interpolation of value from 'ycol' based on the row(s) which bound value 'x' in column 1 of the table. | ||||
t.tablename.PDF(colindex) | Column | Subsystem | References a column of PDF variables for the distribution generator when it is in PDF mode | ||||
t.tablename.CDF(colindex) | Column | Subsystem | References a column of CDF variables for the distribution generator when it is in CDF mode |
Table cells can be referenced as follows:
t.tablename[rowindex][columnindex]
tablename must be quoted, as for attname above.
rowindex and columnindex can be any valid expression.
In addition, if columnindex is quoted, it is treated as a column label.
eg:
t.mytable[i.whichrow][3]
t.mytable[i.whichrow + 1]["Destination"]
t."Table With Spaces In Name"[i.location][t.mappingtable[i.location]["MapColumns"]]
Labels
The index of a label can be read as follows
l.labellistname["label text"]
or the index of a specified member in a label list can be read as follows
l.labellistname[whichlabel]
where whichlabel is an expression giving a number from 1 to the number of labels in the list.
eg:
l._boolean["True"] - yields 1
l._boolean[2] - also yields 1 because "True" is the second member in this list
Expressions are "parsed" when OK is clicked so any syntax errors will be picked up during editing. However attribute names, table columns and label lookups are currently not determined until runtime. Future versions will see this optimised.
idkbase note 316