Expressions

From Planimate Knowledge Base
Revision as of 20:33, 31 July 2009 by Rick (talk | contribs)
Jump to navigation Jump to search

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 one more pieces of data in a Planimate model. Typically such a reference has a type letter, followed by a period then the datum's name.

Attributes:


i.attname item attribute
p.attname portal attribute
r.attname routine attribute
s.attname system attribute


If "attname" contains spaces or non alphabetic/numeric symbols, it must be quoted, otherwise the
quotes can be left out.


eg:


p.attribute
i."next location"
s.clock
s."run number"

Tables:


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