Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [ATL] how to realize a simple loop
[ATL] how to realize a simple loop [message #91605] Wed, 08 October 2008 04:54 Go to next message
Eclipse UserFriend
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 #91632 is a reply to message #91605] Wed, 08 October 2008 05:18 Go to previous messageGo to next message
Eclipse UserFriend
This is a multi-part message in MIME format.
--------------000509060606010609090203
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Rob,

Maybe the following link could help you (especially by using lazy
rules):
http://www.eclipse.org/m2m/atl/basicExamples_Patterns/articl e.php?file=Port/index.html

There are others basic examples available here:
http://www.eclipse.org/m2m/atl/basicExamples_Patterns/

HTH

Regards,
Freddy.

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


--------------000509060606010609090203
Content-Type: text/x-vcard; charset=utf-8;
name="freddy_allilaire.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="freddy_allilaire.vcf"

YmVnaW46dmNhcmQNCmZuOkZyZWRkeSBBbGxpbGFpcmUNCm46QWxsaWxhaXJl O0ZyZWRkeQ0K
b3JnOk9CRU8NCmFkcjo7OzIgcnVlIFJvYmVydCBTY2h1bWFubjtOQU5URVM7 OzQ0NDA4O0Zy
YW5jZQ0KZW1haWw7aW50ZXJuZXQ6ZnJlZGR5LmFsbGlsYWlyZUBvYmVvLmZy DQp0aXRsZTpS
JkQgRW5naW5lZXINCnVybDp3d3cub2Jlby5mcg0KdmVyc2lvbjoyLjENCmVu ZDp2Y2FyZA0K
DQo=
--------------000509060606010609090203--
Re: [ATL] how to realize a simple loop [message #91709 is a reply to message #91605] Wed, 08 October 2008 06:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jihed.touzi.enstimac.fr

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
Re: [ATL] how to realize a simple loop [message #91754 is a reply to message #91709] Wed, 08 October 2008 06:47 Go to previous message
Eclipse UserFriend
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
Previous Topic:[QVTO] Problems occurred when invoking code from plug-in: "org.eclipse.jface".
Next Topic:[QVTO] Text2Model
Goto Forum:
  


Current Time: Sat Aug 30 20:21:40 EDT 2025

Powered by FUDForum. Page generated in 0.04283 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top