Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [ATL] retrieve index of an element in a collection
[ATL] retrieve index of an element in a collection [message #90617] Fri, 26 September 2008 11:34 Go to next message
Eclipse UserFriend
Originally posted by: matteo.risoldi.unige.ch

Hello,

I have a collection of Strings (created by splitting a String). With
these, I need to create a collection of elements. However, the elements
I create must be characterized by a number, specifying their order.

Example:
The collection of Strings is :
Sequence{'p1:int','p2:int','p3:bool}

with this collection I do:

Sequence{'p1:int', 'p2:int', 'p3:bool'} -> collect(p | thisModule.
myRule(p))

lazy rule myRule{
from
pdefinition : String
to
ti : DestMM!T (
name <- pdefinition,
index <- .......

)
}

what could I do to be able to put in place of the dots an integer
saying in what position of the collection that particular string was?
So that it would be 1 for 'p1:int', 2 for 'p2:int' etcetera. I can't
find an obvious way in the collect command to access the current
position of the iteration. I'd like some way I could pass an integer
parameter to myRule, and use it to give a value to index.

Does anybody have a suggestion?
Thank you in advance.

Matteo
Re: [ATL] retrieve index of an element in a collection [message #90633 is a reply to message #90617] Mon, 29 September 2008 04:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mddfabro.ilog.fr

Hello,

one solution is to use called rules, which are rules that are called
with parameters.

Your code could be rewritten in the following way:

let seq : Sequence(String) = Sequence{'p1:int', 'p2:int', 'p3:bool'} in
collect(p | thisModule.myRule(p, seq->indexOf(p) ))

rule myRule (pdefinition : String, aIndex : Integer){
to
ti : DestMM!T (
name <- pdefinition,
index <- aIndex

)
do {
ti; -- this is necessary in order to return the new model element
}
}

Regards,

Marcos.

Matteo Risoldi wrote:
> Hello,
>
> I have a collection of Strings (created by splitting a String). With
> these, I need to create a collection of elements. However, the elements
> I create must be characterized by a number, specifying their order.
>
> Example:
> The collection of Strings is :
> Sequence{'p1:int','p2:int','p3:bool}
>
> with this collection I do:
>
> Sequence{'p1:int', 'p2:int', 'p3:bool'} -> collect(p | thisModule.
> myRule(p))
>
> lazy rule myRule{
> from
> pdefinition : String
> to
> ti : DestMM!T (
> name <- pdefinition,
> index <- .......
>
> )
> }
>
> what could I do to be able to put in place of the dots an integer saying
> in what position of the collection that particular string was? So that
> it would be 1 for 'p1:int', 2 for 'p2:int' etcetera. I can't find an
> obvious way in the collect command to access the current position of the
> iteration. I'd like some way I could pass an integer parameter to
> myRule, and use it to give a value to index.
>
> Does anybody have a suggestion?
> Thank you in advance.
>
> Matteo
>
Re: [ATL] retrieve index of an element in a collection [message #90663 is a reply to message #90633] Mon, 29 September 2008 05:42 Go to previous message
Eclipse UserFriend
Originally posted by: matteo.risoldi.unige.ch

Hi,

great, that works perfectly (I might just add that one needs to put
"seq ->" just after the "in" or you get a "no viable alternative"
error).

Thank you very much!
Matteo


On 2008-09-29 10:22:46 +0200, Marcos Didonet Del Fabro <mddfabro@ilog.fr> said:

> Hello,
>
> one solution is to use called rules, which are rules that are called
> with parameters.
>
> Your code could be rewritten in the following way:
>
> let seq : Sequence(String) = Sequence{'p1:int', 'p2:int', 'p3:bool'} in
> collect(p | thisModule.myRule(p, seq->indexOf(p) ))
>
> rule myRule (pdefinition : String, aIndex : Integer){
> to
> ti : DestMM!T (
> name <- pdefinition,
> index <- aIndex
>
> )
> do {
> ti; -- this is necessary in order to return the new model element
> }
> }
>
> Regards,
>
> Marcos.
>
> Matteo Risoldi wrote:
>> Hello,
>>
>> I have a collection of Strings (created by splitting a String). With
>> these, I need to create a collection of elements. However, the elements
>> I create must be characterized by a number, specifying their order.
>>
>> Example:
>> The collection of Strings is :
>> Sequence{'p1:int','p2:int','p3:bool}
>>
>> with this collection I do:
>>
>> Sequence{'p1:int', 'p2:int', 'p3:bool'} -> collect(p |
>> thisModule. myRule(p))
>>
>> lazy rule myRule{
>> from
>> pdefinition : String
>> to ti : DestMM!T (
>> name <- pdefinition,
>> index <- ....... )
>> }
>>
>> what could I do to be able to put in place of the dots an integer
>> saying in what position of the collection that particular string was?
>> So that it would be 1 for 'p1:int', 2 for 'p2:int' etcetera. I can't
>> find an obvious way in the collect command to access the current
>> position of the iteration. I'd like some way I could pass an integer
>> parameter to myRule, and use it to give a value to index.
>>
>> Does anybody have a suggestion?
>> Thank you in advance.
>>
>> Matteo
Previous Topic:[ATL] load a model from plugins
Next Topic:[ATL] problem with UML2.ecore file
Goto Forum:
  


Current Time: Fri Apr 25 21:44:06 EDT 2025

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

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

Back to the top