On 04/09/2013 13:52, Federico Toledo wrote:
> Hi everyone!
>
> I need to iterate a certain number of times, according with the
> integer value of an attribute.
> Let's say that I have an object 'A' with an attribute 'int_att', and
> I'd like to create as many 'B' as indicated by this attribute.
> I found a solution, but I want to know if there is a better way,
> because I was looking in the documentation and in the forum with no luck.
>
> First I create a collection to have something to iterate
>
> helper def : getCollectionFrom1to(i:Integer) : Collection(Integer) =
> if i>1 then
> thisModule.getCollectionFrom1to(i-1)->including(i) else
> Sequence{1} endif;
>
>
> Then I iterate this collection doing what I need
>
> for (it in thisModule.getCollectionFrom1to(A.int_att)) {
> thisModule.createB(A);
> }
>
>
>
> Thank you in advance for any feedback
Op 04-09-13 15:51, Federico Toledo schreef:
> I guess it is not implemented because it does not compile...
> thank you!
You're right: ATL syntax does not support the OCL range idiom, so ATL cannot
parse it. For regular ATL, your solution is fine.
Note that ATL/EMFTVM introduces a separate operation for including ranges into
a Collection, which is implemented lazily: Collection::includingRange(start :
Integer, end : Integer) : Collection. It does not actually store the whole
range of numbers, but just generates numbers as the collection is evaluated.