Home » Archived » M2M (model-to-model transformation) » [ATL] sequence & collect
[ATL] sequence & collect [message #23707] |
Fri, 16 March 2007 11:39  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #25172 is a reply to message #23990] |
Fri, 23 March 2007 17:56  |
Eclipse User |
|
|
|
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
>
|
|
|
Goto Forum:
Current Time: Wed May 07 17:23:43 EDT 2025
Powered by FUDForum. Page generated in 0.03813 seconds
|