Expressions: Difference between revisions

From Planimate Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
==== Planimate Expression Language  ====
==== Planimate Expression Language  ====


Originally Planimate referenced data using a dialog. This has been augmented with an underlying textual expression language which enables more straightforward mathematical, boolean and string manipulation.  
Previous versions of Planimate referenced data using a dialog based selector. This has been augmented with an underlying textual expression language which enables more straightforward mathematical, boolean and string manipulation.


An INI file default specifies whether references are specified using the text or dialog. You can switch between the two on the fly.
The following lists the operators and types available 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 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).  


{| cellspacing="1" cellpadding="1" border="1" style="width: 621px; height: 339px;"
{| cellspacing="1" cellpadding="1" border="1" style="width: 621px; height: 339px;"
Line 23: Line 21:
| ref.prop  
| ref.prop  
| Property of a referenced datum
| Property of a referenced datum
|-
| [...]
| Index property for tables and lists
|-
|-
| []  
| []  
| Index property for tables and lists
| Denotes an entire item table reference
|-
|-
| function()  
| function()  
Line 93: Line 94:
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.  
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  ====
==== Data 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.  
The most useful ability of expressions is the ability to reference data within 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.  
Most operations expect numeric data. Some expect entire table rows, tables, columns, label lists or text strings. In case where text is needed, Planimate will automatically translate values to their textual form following the format of the container of the value. The $= operation will translate text strings into the format of the container (as well it can) if its not a text format.<br>


{| cellspacing="1" cellpadding="1" border="1" style="width: 621px; height: 339px;"
{| cellspacing="1" cellpadding="1" border="1" style="width: 621px; height: 339px;"
Line 112: Line 113:
|-
|-
| p.attribute  
| p.attribute  
| Value / String
| Value / Text
| Subsystem  
| Subsystem  
| Attribute defined and only visible within a subsystem and the portal/subsystems contained therein.
| Attribute defined and only visible within a subsystem and the portal/subsystems contained therein.
|-
|-
| r.attribute  
| r.attribute  
| Value / String
| Value / Text
| Routine (Change)  
| Routine (Change)  
| Attribute defined within a routine (or subroutine). String attributes are not recursive within subroutines that call themselves but values are.
| Attribute defined within a routine (or subroutine). String attributes are not recursive within subroutines that call themselves but values are.
|-
|-
| s.attname  
| s.attname  
| Value / String
| Value / Text
| System wide  
| System wide  
| System provided access to properties and settings of the runtime environment
| System provided access to properties and settings of the runtime environment
Line 132: Line 133:
|-
|-
| t.tablename[r][c]  
| t.tablename[r][c]  
| Value / String
| Value / Text
| Subsystem  
| Subsystem  
| References a table cell. 'c' can be a column label for the table.
| References a table cell. 'c' can be a column label for the table, such as 'c.Origin' or an index.&nbsp;
|-
|-
| t.tablename  
| t.tablename[]
| Table  
| Table  
| Subsystem  
| Subsystem  
| Reference to an entire table
| Reference to an entire table
|-
|-
| t.tablename.Row(value)  
| t.tablename[].Row(value)  
| Table Row  
| Row  
| Subsystem  
| Subsystem  
| Reference to an entire table row
| Reference to an entire table row
|-
|-
| t.tablename.Column(value)  
| t.tablename[].Column(value)  
| Table Row
| Column
| Subsystem  
| Subsystem  
| Reference to an entire table column
| Reference to an entire table column
Line 154: Line 155:
t.tablename.  
t.tablename.  


&nbsp;MatchedRow(value)  
&nbsp;MatchedRow(keyc,key)  


| Table Row  
| Row  
| Subsystem  
| Subsystem  
| Reference to an entire table row determined by search for a 'key' in a 'column'
| Reference to an entire table row determined by search for a 'key' in column 'keyc'
|-
|-
|  
|  
t.tablename.  
t.tablename[].  


&nbsp;MatchedCell(keycol,col,key)  
&nbsp;MatchedCell(keyc,c,key)  


| Value / String
| Value / Text
| Subsystem  
| Subsystem  
| Reference to a table cell determined by search for a 'key' in a 'keycol'. The cell is taken from column 'col'.
| Reference to a table cell determined by search for a 'key' in column 'keycl'. Once the row is found the cell is taken from column 'c'.
|-
|-
|  
|  
t.tablename.  
t.tablename.  


&nbsp;MatchedIndex(keycol,key)  
&nbsp;MatchedIndex(keyc,key)  


| Value  
| Value  
| Subsystem  
| Subsystem  
| The row number determined by search for a 'key' in a 'keycol'
| The row number determined by search for a 'key' in column 'keyc'
|-
|-
| t.tablename.Remap(x,ycol)  
| &nbsp;t.tablename[].Remap(x,yc)  
| Value  
| Value  
| Subsystem  
| Subsystem  
| Lookup and interpolation of value from 'ycol' based on the row(s) which bound value 'x' in column 1 of the table.
| Lookup and interpolation of value from column 'ycl' 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)
| &nbsp;t.table[r][c].Property  
| Column
| Subsystem
| References a column of CDF variables for the distribution generator when it is in CDF mode
|-
| t.table[r][c].Block
| Cell
| Subsystem
| Converts a cell reference at [r][c] so it can be used to specify the top left cell in a block operation. This operation is due for review and replacement.
|-
| t.table[r][c].Property  
| Value  
| Value  
| Subsystem  
| Subsystem  
| Converts a cell reference at [r][c] so it references the cell colour property data which enables the cells background and foreground colours to be individually set.
| Converts a cell reference at [r][c] so it references the cell colour property data which enables the cells background and foreground colours to be individually set.
|-
|-
| t.Dynamic(usename)  
| &nbsp;t.Dynamic(usename)  
| Table  
| Table  
| Subsystem  
| Subsystem  
| Enables a table to be referenced by name dynamically. 'usename' is interpreted as a string to name the table. Note that matched references cannot be used with this kind of table reference.
| Enables a table to be referenced by name dynamically. 'usename' is interpreted as a string to name the table. Note that matched references cannot be used with this kind of table reference.
|-
|-
| t.tablename.RowCount  
| &nbsp;t.tablename[].RowCount  
| Value  
| Value  
| Subsystem  
| Subsystem  
| References the number of rows in the table
| References the number of rows in the table
|-
|-
| t.tablename.ColumnCount  
| &nbsp;t.tablename[].ColumnCount  
| Value  
| Value  
| Subsystem  
| Subsystem  
| References the number of columns in the table
| References the number of columns in the table
|-
|-
| s.item  
|  
t.tablename[].ColumnIndex("label")
 
| Value
| Subsystem
| Resolves the index of column 'label' in the table.
|-
|
i.itemtablename[]
 
| Table
| Item
| Enables access to an [[Item Table References|item table reference]] which can be dynamically associated with a table in the model and carried to another part of the model by the item, where that table may not be in scope.
|-
| &nbsp;l.labellistname["label"]<br>
| Value<br>
| Subsystem<br>
| Resolves the numerical index associated with text 'label' in the label list 'labellistname'.<br>
|-
| &nbsp;l.labellistname[value]<br>
| Value<br>
| Subsystem<br>
| Resolves the numerical index associated with a label in 'labellistname' where 'value' counts labels starting at 1 for the first.<br>
|-
| &nbsp;l.labellistname
| LabelList
| Subsystem
| Enables a reference to an entire label list where such a reference is required. Note that any other reference involving a label list, either explicitly (like l._colors["black"]) or implicitly, (like p.portalatt where portalatt is formatted for a label list) can be used where a list reference is expected.
|-
| &nbsp;s.item  
| Entire item  
| Entire item  
| Item  
| Item  
| References an entire item. Normally items are implicit and do not need to be referenced for an interaction but this is provided for special item properties.
| References an entire item. Normally items are implicit and do not need to be referenced for an interaction but this is provided for special item properties.
|-
|-
| s.item.Carried(index,name)  
| s.item.Carried(ind,name)  
| Value  
| Value  
| Item  
| Item  
| References an attribue 'name' on an item being carried by the current item. 'index' specifies which item, it can be a number like 1 for the first item, s.ItemsCarried uses the system attribute to get the last item picked up or i.CARRYINDEX enables use of a modeller created attribute which must be named CARRYINDEX to determine which carried item the reference will refer to.
| References an attribue 'name' on an item being carried by the current item. 'ind' specifies which item, it can be a number like 1 for the first item, s.ItemsCarried uses the system attribute to get the last item picked up or i.CARRYINDEX enables use of a modeller created attribute which must be named CARRYINDEX to determine which carried item the reference will refer to.
|-
|-
| (reference).objectproperty
| &nbsp; (ref).ObjectProperty
| Value  
| Value  
| Object  
| Object  
| Interprets the value of 'reference' as an object index and returns object property 'objectproperty' for that object, eg: p.fromportal.ObjectXPosition would retrieve the co-ordinate for the portal object referenced by a portal attribute 'fromportal'.
| Interprets the value of 'ref' as an object index and returns object property 'objectproperty' for that object, eg: p.fromportal.ObjectXPosition would retrieve the co-ordinate for the portal object referenced by a portal attribute 'fromportal'.
|}
|}


Notes:  
Notes:  


Attribute/table/list names must be quoted if they contain spaces or characters apart from letters, numbers and underscore. Future versions will remove support for names with characters needing quotes.  
Attribute/table/list names must be quoted if they contain spaces or characters apart from letters, numbers and underscore. Future versions will remove support for names with characters needing quotes so update older models accordingly.  
 
<br>
 
l.labellistname["label text"]
l.labellistname[whichlabel]
 
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>


<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.
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 not verified until runtime.&nbsp;


[[Category:Attribute]] [[Category:Labellist]] [[Category:Routine]] [[Category:Table]]
[[Category:Attribute]] [[Category:Labellist]] [[Category:Routine]] [[Category:Table]]

Latest revision as of 19:04, 22 April 2010

Planimate Expression Language

Previous versions of Planimate referenced data using a dialog based selector. This has been augmented with an underlying textual expression language which enables more straightforward mathematical, boolean and string manipulation.

The following lists the operators and types available 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
[] Denotes an entire item table reference
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.

Data References

The most useful ability of expressions is the ability to reference data within 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 text strings. In case where text is needed, Planimate will automatically translate values to their textual form following the format of the container of the value. The $= operation will translate text strings into the format of the container (as well it can) if its not a text format.

Example Type Context comments
i.attribute Value Item Attribute defined for an item class but uniquely settable for each
p.attribute Value / Text Subsystem Attribute defined and only visible within a subsystem and the portal/subsystems contained therein.
r.attribute Value / Text 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 / Text System wide System provided access to properties and settings of the runtime environment
b.name Value Global Enables a labelled constant to be used instead of 0 or 1. 'name' can be FALSE, NO or OFF for 0 and TRUE, YES or ON for 1. This can help make code intent clearer without any impact on performance in looking up a normal attribute or label value.
t.tablename[r][c] Value / Text Subsystem References a table cell. 'c' can be a column label for the table, such as 'c.Origin' or an index. 
t.tablename[] Table Subsystem Reference to an entire table
t.tablename[].Row(value) Row Subsystem Reference to an entire table row
t.tablename[].Column(value) Column Subsystem Reference to an entire table column

t.tablename.

 MatchedRow(keyc,key)

Row Subsystem Reference to an entire table row determined by search for a 'key' in column 'keyc'

t.tablename[].

 MatchedCell(keyc,c,key)

Value / Text Subsystem Reference to a table cell determined by search for a 'key' in column 'keycl'. Once the row is found the cell is taken from column 'c'.

t.tablename.

 MatchedIndex(keyc,key)

Value Subsystem The row number determined by search for a 'key' in column 'keyc'
 t.tablename[].Remap(x,yc) Value Subsystem Lookup and interpolation of value from column 'ycl' based on the row(s) which bound value 'x' in column 1 of the table.
 t.table[r][c].Property Value Subsystem Converts a cell reference at [r][c] so it references the cell colour property data which enables the cells background and foreground colours to be individually set.
 t.Dynamic(usename) Table Subsystem Enables a table to be referenced by name dynamically. 'usename' is interpreted as a string to name the table. Note that matched references cannot be used with this kind of table reference.
 t.tablename[].RowCount Value Subsystem References the number of rows in the table
 t.tablename[].ColumnCount Value Subsystem References the number of columns in the table

t.tablename[].ColumnIndex("label")

Value Subsystem Resolves the index of column 'label' in the table.

i.itemtablename[]

Table Item Enables access to an item table reference which can be dynamically associated with a table in the model and carried to another part of the model by the item, where that table may not be in scope.
 l.labellistname["label"]
Value
Subsystem
Resolves the numerical index associated with text 'label' in the label list 'labellistname'.
 l.labellistname[value]
Value
Subsystem
Resolves the numerical index associated with a label in 'labellistname' where 'value' counts labels starting at 1 for the first.
 l.labellistname LabelList Subsystem Enables a reference to an entire label list where such a reference is required. Note that any other reference involving a label list, either explicitly (like l._colors["black"]) or implicitly, (like p.portalatt where portalatt is formatted for a label list) can be used where a list reference is expected.
 s.item Entire item Item References an entire item. Normally items are implicit and do not need to be referenced for an interaction but this is provided for special item properties.
s.item.Carried(ind,name) Value Item References an attribue 'name' on an item being carried by the current item. 'ind' specifies which item, it can be a number like 1 for the first item, s.ItemsCarried uses the system attribute to get the last item picked up or i.CARRYINDEX enables use of a modeller created attribute which must be named CARRYINDEX to determine which carried item the reference will refer to.
  (ref).ObjectProperty Value Object Interprets the value of 'ref' as an object index and returns object property 'objectproperty' for that object, eg: p.fromportal.ObjectXPosition would retrieve the co-ordinate for the portal object referenced by a portal attribute 'fromportal'.

Notes:

Attribute/table/list names must be quoted if they contain spaces or characters apart from letters, numbers and underscore. Future versions will remove support for names with characters needing quotes so update older models accordingly.

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 not verified until runtime.