Recursive Functions

Is it possible to write recursive functions in M2Doc?
I would like to structure part of my output document based on the functional breakdown of my system.
Top Level Function

  • Child Function 1
  • Child of Child Function 1
  • Child Function 2
  • Child of Child Function 2
  • Child of Child Function 2
    The best way I think of to achieve this would be a recursive function. But I’m not sure if this is possible or how I might do it?
    The alternative would be to hardcode a few levels of recursion in the template using for loops and if statements. But this would set a hard limit on the number of levels the functions could be decomposed into, which is why I was trying to avoid it.

It’s possible using
template constructs. It’s basically a function you can call, and you can call it recursively.
You can find a complete exemple

You could also use the closure operation from ocl to create recursive expressions. I have used it to create the kind of structure you are looking for for my logical components using the code
{m:for subLogicalComponent | RootLogicalComponent.eContents(la::LogicalComponent)->closure(logicalComponent | logicalComponentc.eContents(la::LogicalComponent))}

I have renamed the variables for you to make them explicit. Hopefully you find this helpful!

Hello Yvan
Could you please attach again your example ? I am trying to code this, and I have the feeling it could save my life.
By the way : let me wish you an happy new years ! with plenty of stars and galaxy :slightly_smiling_face:

Pierre Campan

Ok, finally inspiration struck me last night and I found your script in the old forum !!!

I think it was this example:

Yes, I was not able to use it because I am not fluent in Template usage … I go one trying

Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.