Closure operation added to OCL

Tweet about this on TwitterShare on FacebookBuffer this pageShare on RedditShare on LinkedInShare on Google+Email this to someone

This is big news! Now OCL has a closure operation (thanks to Martin for alerting me ). This means that now in OCL you could write something like parents->closure(children) to compute the set of parents.children, parents.children.children, parents.children.children.children etc.

I’ve been missing this feature for a long time since I found similar situations very often and I was tired of specifying recursive OCL operations to simulate the closure myself.

From the OCL standard 2.3 Beta 2 :  Closure operation uses the same syntax as the select and reject iterators and is written as one of

  • source>closure( v : Type | expression-with-v )
  • source>closure( v | expression-with-v )
  • source>closure( expression )

The returned collection of the closure iteration is an accumulation of the source, and the collections resulting from the recursive invocation of expression-with-v in which v is associated exactly once with each distinct element of the returned collection. The iteration terminates when expression-with-v returns empty collections or collections containing only already accumulated elements. The collection type of the result collection is the unique form (Set or OrderedSet) of the original source collection. If the source collection is ordered, the result is in depth first preorder.

So, what’s your opinion? Are you happy with this new feature? Were you missing it?

Tweet about this on TwitterShare on FacebookBuffer this pageShare on RedditShare on LinkedInShare on Google+Email this to someone
Comments
  1. Alejandro
  2. Joern Guy Suess
  3. Sashir Estela

Reply

Your email address will not be published. Required fields are marked *