[ATL] how to realize a simple loop [message #91605] |
Wed, 08 October 2008 04:54  |
Eclipse User |
|
|
|
Originally posted by: robert.meyer.campus.lmu.de
Hi,
I am very new to ATL and functional programming - that´s why I have a
little problem:
I want to realize something like a for-loop in a matched rule (that´s
what I would do normally) - I would be very thankful for a
best-practice-example how to realize this in ATL:
My Model:
RootObject
-Object 1 (some properties)
-Object 2 (some properties)
-- Literal Unlimted Natural (Value = 5)
-- Literal Integer (Value = 5)
-Object 3 (some properties)
I want to match the Objects and create some instances in the target
model. At the moment I match the RootObject with a matched rule and
create the instances by iterating through the Objects with distinct.
That works fine - except if I want to create more than one Instance of
the same Object (like Object 2 in the example).
I tried to created a nested forEach, but I don´t know how...
So my question: How to interate from 1 to 5 and create 5 instances of
Object 2? What would you do?
Thanks for your help, i would really like to learn ATL, but the
beginning is hard sometimes...
Rob
|
|
|
|
|
Re: [ATL] how to realize a simple loop [message #91754 is a reply to message #91709] |
Wed, 08 October 2008 06:47  |
Eclipse User |
|
|
|
Originally posted by: robert.meyer.campus.lmu.de
Hi Jihed,
thank you very much, I think that this is exactly what I was looking for!
It´s really a clever way to get the standard-imperative-things with a
recursive algorithm!
Rob
jihed touzi schrieb:
> Hi Robert
> Actually you can't use a while pattern with ATL because simpy it doesn't
> exist.
>
> But you can use an equivalent to that according to algorithmics
> principles. your problem is not only an ATL problem
> : You have to use a recursive call of an ATL called rule joined to If
> pattern use.
> Below an example.
>
>
> Supposes that you want do that
> x=1
> While x< 5
> do { x<-x+1 }
>
> with ATL you do that:
>
> x<-1
> thisModule.Calcul (x);
>
> rule Calcul (x: integer)
> do{
> if (x<5)
> {x<-x+1;
> thisModule.Calcul (x);}}
>
> Jihed
>
>
>
>
>
> exquisitus a écrit :
>> Hi,
>>
>> I am very new to ATL and functional programming - that´s why I have a
>> little problem:
>>
>> I want to realize something like a for-loop in a matched rule (that´s
>> what I would do normally) - I would be very thankful for a
>> best-practice-example how to realize this in ATL:
>>
>> My Model:
>> RootObject
>> -Object 1 (some properties)
>> -Object 2 (some properties)
>> -- Literal Unlimted Natural (Value = 5)
>> -- Literal Integer (Value = 5)
>> -Object 3 (some properties)
>>
>> I want to match the Objects and create some instances in the target
>> model. At the moment I match the RootObject with a matched rule and
>> create the instances by iterating through the Objects with distinct.
>> That works fine - except if I want to create more than one Instance of
>> the same Object (like Object 2 in the example).
>>
>> I tried to created a nested forEach, but I don´t know how...
>>
>> So my question: How to interate from 1 to 5 and create 5 instances of
>> Object 2? What would you do?
>>
>> Thanks for your help, i would really like to learn ATL, but the
>> beginning is hard sometimes...
>>
>> Rob
|
|
|
Powered by
FUDForum. Page generated in 0.04283 seconds