OCLOperators whentrue
No edit summary
No edit summary
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
When having immutable ocl expression you always return a value - and the the [[OCLOperators_TrueFalse]] is good, but when using the MDriven Action-Language that allows updates of objects another construct is introduced to compact things even more:
<message>Write the content here to display this box</message>
When you have an immutable OCL expression, you always return a value - and then the [[Documentation:OCLOperators casetruefalse|OCLOperators_caseTrueFalse]] is good. However, when using the MDriven Action-Language that allows updates of objects, another construct is introduced to compact things even more:
boolean.whentrue(dothis):boolean
The return is always the '''arg0'''.


boolean.case(dothis):boolean
=== '''Example:''' ===
let x=SomeObject.SomeEnum in (  
  (x=#Enum1).whentrue(SomeObject.DoYourThing1);  
  (x=#Enum2).whentrue(SomeObject.DoYourThing2);  
  (x=#Enum3).whentrue(SomeObject.DoYourThing3)
)
'''''Fun fact:''''' "whentrue" and logical "and" are implemented the same - the logical "and" only evaluates arg1 of arg0 is true (lazy evaluation) and "whentrue" does the same thing, but always returns arg0.


Example:
This means that a convoluted but equivalent construct can be:
  let x=SomeObject.SomeEnum in (  
  let x=SomeObject.SomeEnum in (  
   (x=#Enum1).case(SomeObject.DoYourThing1);  
   (x=#Enum1) and (SomeObject.DoYourThing1;true);  
   (x=#Enum2).case(SomeObject.DoYourThing2);  
   (x=#Enum2) and (SomeObject.DoYourThing2;true);  
   (x=#Enum3).case(SomeObject.DoYourThing3)  
   (x=#Enum3) and (SomeObject.DoYourThing3;true)  
  )
  )
  [[Category:OCLOperators]]
{{Edited|July|12|2025}}

Latest revision as of 04:56, 11 February 2025

This page was created by Hans.karlsen@mdriven.net on 2021-12-04. Last edited by Stephanie@mdriven.net on 2025-02-11.

When you have an immutable OCL expression, you always return a value - and then the OCLOperators_caseTrueFalse is good. However, when using the MDriven Action-Language that allows updates of objects, another construct is introduced to compact things even more:

boolean.whentrue(dothis):boolean

The return is always the arg0.

Example:

let x=SomeObject.SomeEnum in (  
  (x=#Enum1).whentrue(SomeObject.DoYourThing1);  
  (x=#Enum2).whentrue(SomeObject.DoYourThing2);  
  (x=#Enum3).whentrue(SomeObject.DoYourThing3) 
)

Fun fact: "whentrue" and logical "and" are implemented the same - the logical "and" only evaluates arg1 of arg0 is true (lazy evaluation) and "whentrue" does the same thing, but always returns arg0.

This means that a convoluted but equivalent construct can be:

let x=SomeObject.SomeEnum in (  
  (x=#Enum1) and (SomeObject.DoYourThing1;true);  
  (x=#Enum2) and (SomeObject.DoYourThing2;true);  
  (x=#Enum3) and (SomeObject.DoYourThing3;true) 
)