User Tools

Site Tools


syntax:operators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
syntax:operators [2016/06/08 21:11] dmitrysyntax:operators [2021/01/13 18:43] (current) dmitry
Line 1: Line 1:
 ====== Operators ====== ====== Operators ======
  
-Here is list of operators that can be used in expressions in EasyMorph.+Here is list of operators that can be used in expressions in EasyMorph. 
 + 
 +=== Basic operators ===
  
 ^  Operator  ^ Description  ^ Result    ^ ^  Operator  ^ Description  ^ Result    ^
Line 30: Line 32:
      
   ([Amount] > 1000 and [Quantity] > 1) or [Quantity]>10   ([Amount] > 1000 and [Quantity] > 1) or [Quantity]>10
 +  
 +=== The IF..THEN..ELSE operator ===
 +This operator can be used to perform conditional calculations. It has the following syntax:
 +
 +IF //condition// THEN //expression// ELSE //expression//
 +
 +A shorter form where the ELSE expression is omitted and always returns an empty value is also possible:
 +
 +IF //condition// THEN //expression//
 +
 +Note that unlike the [[syntax:functions:if|if()]] function, in the IF operator the "then" expression is only evaluated when the condition is TRUE. The "else" expression in this case is not evaluated (i.e. ignored). Vice versa, if the condition is FALSE, then the "then" expression is ignored, and only the "else" expression is evaluated.
 +
 +Examples:
 +
 +   IF [Amount] > 1000 THEN 'Large order' ELSE 'Small order'
 +
 +   IF [Year] = year(today()) THEN [Amount] ELSE 0
 +
 +   IF [Qty] = 0 THEN 0 ELSE [Amount] / [Qty]   // Doesn't fail when [Qty] = 0
 +  
 +=== The LET operator ===
 +The LET operator allows simplifying expressions by declaring repetitive parts as local constants which can later be used instead of the repetitive parts. The operator has the following syntax:
 +
 +LET //local_constant// = //expression//
 +
 +Once a local constant is declared, it can be used in the expression(s) that follow the declaration. Example:
 +
 +   LET d = day(today())
 +   IF d=1 THEN 'First day' ELSE 'Day: ' & d
 +   
 +=== The ASSUME operator ===
 +The operator allows creating guarding conditions that must evaluate to TRUE before the expression is evaluated. ASSUME can be used to ensure data quality and integrity right in expressions. The operator has the following syntax:
 +
 +ASSUME //expression//
 +
 +ASSUME //expression// OTHERWISE FAIL //expression//
 +
 +Examples:
 +
 +   ASSUME [Tax]>=0 
 +   [Amount] + [Tax]
 +
 +In the expression above, the final statement will only be calculated if [Tax] is not negative. Otherwise, project execution will be aborted with a generic error.
 +
 +It is also possible to specify a custom error message as follows:
 +
 +   ASSUME [Tax]>=0 OTHERWISE FAIL "Tax must not be negative"
 +
 +The OTHERWISE keyword is optional. It can be safely omitted: 
 +
 +   ASSUME [Tax]>=0 FAIL "Tax must not be negative"
 +
 +ASSUME can be used together with the other operators. For instance:
 +
 +   ASSUME isnumber({Tax Rate}) OTHERWISE FAIL ("Invalid tax rate: " & {Tax Rate})
 +   LET tax = [Tax base] * {Tax Rate} - [Tax credit]
 +   ASSUME tax >= 0 OTHERWISE FAIL "Tax must not be negative"
 +   [Amount] + tax
 +
 +
syntax/operators.1465434702.txt.gz · Last modified: 2016/06/08 21:11 by dmitry

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki