Skip to main content



      Home
Home » Archived » M2M (model-to-model transformation) » [ATL] sequence & collect
[ATL] sequence & collect [message #23707] Fri, 16 March 2007 11:39 Go to next message
Eclipse UserFriend
Originally posted by: not.provided.info

observe strange effect with sequence & collect:

items <- Sequence { classes->collect( class | thisModule.Do( class ) ) }

lazy rule Do {
...
to
a : MM!A { refB <- b },
b : MM!B { refC <- c },
c : MM!C {},
aa : MM!A { refB <- bb },
bb : MM!B { refC <- cc },
cc : MM!C {}
}

produces a in the items sequence and aa not in the items sequence. Why
this happen? I suggest, that must be items={a,aa}, not items={a}
Re: [ATL] sequence & collect [message #23750 is a reply to message #23707] Fri, 16 March 2007 13:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikael.barbero.gmail.com

Hi,

What about doing this:

items <- Sequence { classes->collect( class | thisModule.Do( class ) ) }
-> union(Sequence { classes->collect( class | thisModule.Do( class ) ) })

lazy rule Do {
...
to
a : MM!A { refB <- b },
b : MM!B { refC <- c },
c : MM!C {}
-- aa : MM!A { refB <- bb },
-- bb : MM!B { refC <- cc },
-- cc : MM!C {}
}

Then you will have two MM!A element in items (as "aa" is the same as "a")

Or maybe you should try to do this:

lazy rule Do {
...
to
a : MM!A { refB <- b },
b : MM!B { refC <- c },
c : MM!C {}
aa : MM!A { refB <- bb },
bb : MM!B { refC <- cc },
cc : MM!C {}
do {
Sequence{a, aa};
}
}


Be careful, i'm not sure that this latter trick will work as well as
with called rules
( http://wiki.eclipse.org/index.php/ATL_Language_Troubleshoote r#ATL_Called_Rules_Troubles)

Regards,
Mikael

Gediminas wrote:
>
> observe strange effect with sequence & collect:
>
> items <- Sequence { classes->collect( class | thisModule.Do( class ) ) }
>
> lazy rule Do {
> ...
> to
> a : MM!A { refB <- b },
> b : MM!B { refC <- c },
> c : MM!C {},
> aa : MM!A { refB <- bb },
> bb : MM!B { refC <- cc },
> cc : MM!C {}
> }
>
> produces a in the items sequence and aa not in the items sequence. Why
> this happen? I suggest, that must be items={a,aa}, not items={a}
>



--
Mikaël Barbero - PhD Candidate
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssinière
44322 Nantes Cedex 3 - France
tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
http://www.sciences.univ-nantes.fr/lina/atl/
Re: [ATL] sequence & collect [message #23793 is a reply to message #23750] Fri, 16 March 2007 13:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: not.provided.info

Mikael, I'll try, but in my case a is not the same as aa - only types
matches; there are no errors or warnings of bad types & etc

And I suppose, collect should store bothh (a and aa) in a collection. Why
collect so behaves? is this ATL feature?
Re: [ATL] sequence & collect [message #23872 is a reply to message #23793] Fri, 16 March 2007 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikael.barbero.gmail.com

Collect() should not store a and aa with their types. Collect() only
apply an Ocl expression to each element of a collection. This ocl
expression is your lazy rule returning one or more elements.

Regards,
Mikael

Gediminas wrote:
>
> Mikael, I'll try, but in my case a is not the same as aa - only types
> matches; there are no errors or warnings of bad types & etc
>
> And I suppose, collect should store bothh (a and aa) in a collection.
> Why collect so behaves? is this ATL feature?
>
>
>



--
Mikaël Barbero - PhD Candidate
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssinière
44322 Nantes Cedex 3 - France
tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
http://www.sciences.univ-nantes.fr/lina/atl/
Re: [ATL] sequence & collect [message #23990 is a reply to message #23872] Sun, 18 March 2007 06:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: not.provided.info

agree, but if to follow my example, collect returns a and aa for storing
them in the sequence. And I expected, that both will be contained in the
sequence, and not expected, that only the first one (a) is stored while
leaving aa outside sequence. Lazy rule creates all elements as expected,
then it's unclear for me, why happens this effect - maybe I miss something
fundamental about collect/sequence/lazy rule?

It would be interesting to hear Frederic's comment on this
Re: [ATL] sequence & collect [message #25172 is a reply to message #23990] Fri, 23 March 2007 17:56 Go to previous message
Eclipse UserFriend
Hello,


Your problem has nothing to do with collect/sequence but with the way
ATL rules (standard and lazy) work.


* About standard rules:

When used to initialize a property of a target element, a source element
is by default resolved into the first target element of the standard
rule that transformed it. If you need to refer to other target elements
then you can use resolveTemp.


If you want to get two target elements, you need to write an expression
like:

classes->collect(e | Sequence {thisModule.resolveTemp(e, 'first'),
thisModule.resolveTemp(e, 'second')})->flatten()

If one of them is the default (i.e., first) element, then you may simply
put e instead of using resolveTemp.


* About lazy rules:

The current implementation of lazy rules requires explicit call but
behaves similarly to standard rules: only the default (i.e., first)
element is returned from a given source element.
There is no equivalent of resolveTemp for lazy rules yet.





In your case, I believe the best solution is the one given by Mikaël in
his first answer: calling the following rule twice:

lazy rule Do {
...
to
a : MM!A { refB <- b },
b : MM!B { refC <- c },
c : MM!C {}
}



Because your rule is not *unique* (i.e., there is no *unique* keyword
before *lazy*) a new set of a, b, and c elements is created each time
the rule is called. In this case it even makes the copy-and-paste from
(a, b, c) to (aa, bb, cc) useless. Note that it works because the
patterns (a, b, c) and (aa, bb, cc) are the same.

If the patterns were different (and not connected), you could simply
define two lazy rules: one for each pattern.


Best regards,

Frédéric Jouault


Gediminas wrote:
> agree, but if to follow my example, collect returns a and aa for storing
> them in the sequence. And I expected, that both will be contained in the
> sequence, and not expected, that only the first one (a) is stored while
> leaving aa outside sequence. Lazy rule creates all elements as expected,
> then it's unclear for me, why happens this effect - maybe I miss
> something fundamental about collect/sequence/lazy rule?
>
> It would be interesting to hear Frederic's comment on this
>
Previous Topic:[ATL]on defining source and domains with more than one element
Next Topic:Pass a parameters in atl command lines
Goto Forum:
  


Current Time: Wed May 07 17:23:43 EDT 2025

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

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

Back to the top