Expressions

From Planimate Knowledge Base
Revision as of 17:29, 10 January 2008 by Craig.Chandler (talk | contribs)
Jump to navigation Jump to search

Planimate Expression Language

Planimate supports numerical expressions. These can be entered in an Attribute Reference which has been configured as "Expression". They enable more complex mathematical and logical formulae to be expressed in an algebraic form rather than over multiple lines of routine code.


The following mathematical and logical operators 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.


() Enforce precedence
 ! Not operator. Logical not of following value. !0 = 1, !1 = 0, !!3.5 = 1
* / % Multiply, divide and remainder of values either side
+ - Add, subtract of values either side
< <=
> >= Arithmetic comparison of values, yields 1 for true, 0 for false
== != Test for values being equal, not equal (following PL precision rules)
^ Logical (not bitwise) exclusive OR of 2 values, 1 ^ 0 = 1, 1 ^ 1 = 0. Any non zero value is 1
&& Logical AND of 2 values. Any non zero value is considered 1.
|| Logical OR of 2 values. Any non zero value is considered 1.


Hence expressions follow BODMAS rules so a*b+c*d will evaluate as (a*b)+(c*d). Unneeded brackets are generally removed however brackets are placed around complex operations around && and || to aid in legibility.


As well as the operators above, the following functions are available.


sqrt(x) square root
sqr(x) square (x * x)
fabs() removes the sign of x so its always positive
round(x) rounds x to closest integer
trunc(x) removes fraction of x, leaving just integer part
ceil(x) lowest integer which is >= x
floor(x) highest integer which is <= x
exp(x) e to the power of x
ln(x) natural log of x
log10(x) base 10 log of x
pow10(x) 10 to the power of x
pow2(x) 2 to the power of x


cos(x)
sin(x) trig functions, x in radians
tan(x)


acos(x)
asin(x) arc-trig functions, return radians
atan(x)


Attribute references:


Expressions can also reference data in a Planimate model:

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