OCL 2.5 RTF Avatar
  1. OMG Issue

OCL25 — Illegal side-effecting example

  • Key: OCL25-220
  • Status: open  
  • Source: Model Driven Solutions ( Dr. Edward Willink)
  • Summary:

    The flawed resolution of issue 8937 introduced Section 7.5.10 and the Employee::id() example that invokes the static Employee::uniqueID() to initialize each Employee instance with a presumably distinct unique id.

    This can only work if uniqueID() returns a distinct value from each call. It is therefore not a query and not side-effect-free. It cannot be invoked from OCL.

    Unless the execution semantics introduces some new magic static-time between load-time and run-time in which a side-effecting static semantics is defined and supported, this is impossible. No idea how this could be made deterministic on a multi-processor execution engine.

    Rather we need to be declarative and do everything at once, rather than one at a time imperatively.

    context Employee
    static def: allEmployees : Sequence(Employee)
    = Employee.allInstances()->asSequence()
    def: id : String
    = 'ID' + allEmployees->indexOf(self).toString()

    The quadratic cost of indexOf can be avoided if we have maps and co-iterators:

    context Employee
    static def: employee2index : Map(Employee,Integer)
    = Employee.allInstances()->collectByValue(key with value | key)
    def: id : String
    = 'ID' + employee2index->at(self).toString()

    An optimized execution engine could recognize the idiom and optimize away the single use static Map.

  • Reported: OCL 2.4 — Sat, 18 Dec 2021 15:00 GMT
  • Updated: Sat, 18 Dec 2021 15:00 GMT