Expressions: Difference between revisions

From Planimate Knowledge Base
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
'''Planimate Expression Language<br />'''<br /> 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.
'''Planimate Expression Language<br>'''<br> 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.  


<br> 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).


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.
{| cellspacing="1" cellpadding="1" border="1" style="width: 621px; height: 339px;"
|-
| 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
|-
| &nbsp;!
| Logical NOT,&nbsp;!1=0,&nbsp;!123=0,&nbsp;!0=1
|-
| /
| Arithmetic divide
|-
| &nbsp;%
| Arithmetic modulus
|-
| *
| Arithmetic multiply
|-
| +
| Arithmetic add
|-
| -
| Arithmetic subtract
|-
| &lt;
| Logical less than
|-
| &lt;=
| Logical less than or equal
|-
| &gt;
| Logical greater than
|-
| &gt;=
| Logical greater than or equal
|-
| ==
| Logical equal (values follow PL's equality check rules)
|-
| &nbsp;!=
| Logical not equal
|-
| ^
| Logical exclusive-or 0^0=0, 0^1=1, 1^0=1, 1^1=0
|-
| &amp;&amp;
| Logical AND
|-
| &#124;&#124;
| Logical OR
|-
| &amp;
| String concatenate
|-
| ,
| Comma separator for parameters to functions
|}


<br>


() Enforce precedence<br /> ! Not operator. Logical not of following value. !0 = 1, !1 = 0, !!3.5 = 1<br /> * / % Multiply, divide and remainder of values either side<br /> + - Add, subtract of values either side<br /> &lt; &lt;=<br /> &gt; &gt;= Arithmetic comparison of values, yields 1 for true, 0 for false<br /> == != Test for values being equal, not equal (following PL precision rules)<br /> ^ Logical (not bitwise) exclusive OR of 2 values, 1 ^ 0 = 1, 1 ^ 1 = 0. Any non zero value is 1<br /> &amp;&amp; Logical AND of 2 values. Any non zero value is considered 1.<br /> || Logical OR of 2 values. Any non zero value is considered 1.
Brackets () can be used to force order, eg:&nbsp;&nbsp; (a + b) * c


==== Functions  ====


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 &amp;&amp; and || to aid in legibility.
As well as the operators above, a number of [[Functions|functions]] can be used. These can be nested and are particularly useful for complex math and string manipulation.  


==== References  ====


As well as the operators above, the following functions are available.
===== 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.<br><br><u></u>Attributes:  =====


<br> i.attname item attribute<br> p.attname portal attribute<br> r.attname routine attribute<br> s.attname system attribute<br>


sqrt(x) square root<br /> sqr(x) square (x * x)<br /> fabs() removes the sign of x so its always positive<br /> round(x) rounds x to closest integer<br /> trunc(x) removes fraction of x, leaving just integer part<br /> ceil(x) lowest integer which is &gt;= x<br /> floor(x) highest integer which is &lt;= x<br /> exp(x) e to the power of x<br /> ln(x) natural log of x<br /> log10(x) base 10 log of x<br /> pow10(x) 10 to the power of x<br /> pow2(x) 2 to the power of x
<br> If "attname" contains spaces or non alphabetic/numeric symbols, it must be quoted, otherwise the<br> quotes can be left out.


<br> eg:


cos(x) <br /> sin(x) trig functions, x in radians<br /> tan(x)
<br> p.attribute<br> i."next location"<br> s.clock<br> s."run number"<br><br><u>Tables:</u>  


<br> Table cells can be referenced as follows:


acos(x)<br /> asin(x) arc-trig functions, return radians<br /> atan(x)
<br> t.tablename[rowindex][columnindex]


<br> tablename must be quoted, as for attname above.<br> rowindex and columnindex can be any valid expression.<br> In addition, if columnindex is quoted, it is treated as a column label.


Attribute references:
<br> eg:  


<br> t.mytable[i.whichrow][3]<br> t.mytable[i.whichrow + 1]["Destination"]<br> t."Table With Spaces In Name"[i.location][t.mappingtable[i.location]["MapColumns"]]<br><br><br><u>Labels</u>


Expressions can also reference data in a Planimate model:<br /><br /><u>Attributes:</u>
<br> The index of a label can be read as follows


<br> l.labellistname["label text"]


i.attname item attribute<br /> p.attname portal attribute<br /> r.attname routine attribute<br /> s.attname system attribute<br />
<br> or the index of a specified member in a label list can be read as follows


<br> l.labellistname[whichlabel]


If "attname" contains spaces or non alphabetic/numeric symbols, it must be quoted, otherwise the<br /> quotes can be left out.
<br> where whichlabel is an expression giving a number from 1 to the number of labels in the list.  


<br> eg:<br> l._boolean["True"] - yields 1<br> l._boolean[2] - also yields 1 because "True" is the second member in this list <br>


eg:
<br> 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.


p.attribute<br /> i."next location"<br /> s.clock<br /> s."run number"<br /><br /><u>Tables:</u>
Table cells can be referenced as follows:
t.tablename[rowindex][columnindex]
tablename must be quoted, as for attname above.<br /> rowindex and columnindex can be any valid expression.<br /> In addition, if columnindex is quoted, it is treated as a column label.
eg:
t.mytable[i.whichrow][3]<br /> t.mytable[i.whichrow + 1]["Destination"]<br /> t."Table With Spaces In Name"[i.location][t.mappingtable[i.location]["MapColumns"]]<br /><br /><br /><u>Labels</u>
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:<br /> l._boolean["True"] - yields 1<br /> l._boolean[2] - also yields 1 because "True" is the second member in this list <br />
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.
----
----


<br>


<br>


<br> <font size="2">idkbase note 316</font>


 
[[Category:Attribute]] [[Category:Labellist]] [[Category:Routine]] [[Category:Table]]
 
<font size="2">idkbase note 316</font>
 
[[Category:Attribute]]
[[Category:Labellist]]
[[Category:Routine]]
[[Category:Table]]

Revision as of 19:33, 31 July 2009

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