|
Funny, I kind of http://www.metacase.com/forums/topic855_post2144.html#2144" rel="nofollow - guessed you were facing this problem :). Do you have any freedom in the modeling language, or is it already existing and must be implemented as-is? Having unrestricted references like that makes life hard for modelers too - everything can rely on anything else, and it's easy to build cycles or spaghetti then.
With an Object that has a References property, which contains a collection of Objects, there's no way for a single loop to iterate over everything in the right order. (Not a MERL issue, just a fact of that kind of structure.) Instead, you generally proceed by recursion: process this object, recurse to each element in :References that you haven't met before. E.g. the code below will print each Object exactly once, listing its References, and recursing throughout the whole transitively reachable collection of Objects, without duplication or going into an infinite loop on cycles:
_handleObject()if __Unique() then id newline /* write the definition of this object itself */ do :References { ' - ' id newline } do :References { _handleObject() } endif |
You can start it off with a simple "foreach .Object { _handleObject() }". Where the references to the next objects are by relationships not properties, you can tell MERL to start at the top of the tree (or forest): "foreach .Object; where not ~To { _handleObject() }".
I can't see a way out of needing to tell MERL a) where to start from, b) how to navigate on from there, and c) how to avoid duplicates/cycles. They're different each time, so you need your own line of code for them. The good news is that it really is just one line of code for each - the rest above is for the output.
|