Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Question about Called and Unique Lazy Rules
[ATL] Question about Called and Unique Lazy Rules [message #642431] Wed, 01 December 2010 10:17 Go to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Hi all,

I have a question about called and lazy rules. I'm not totally clear
what the "return value" of a called or lazy rule is. Let's take the
example from the User Guide:

lazy rule getCross {
from
i: ecore!EObject
to
rel: metamodel!Relationship (
)
}

And here its invocation:

rule Example {
from
s : ecore!EObject
to
t : metamodel!Node (
name <- s.toString(),
edges <- thisModule.getCross(s) -- ***
)
}

What does the marked line mean exactly? I mean, speaking of the name of
the edges reference, I consider it to be a set, but getCross() seems to
return just one element. Is that automatically converted to a set? I
had expect something like

edges <- Set{ thisModule.getCross(s) }

Especially since the next example uses collect() to produce a set:

edges <- ecore!EClass.allInstancesFrom('yourmodel')->
collect(e | thisModule.getCross(e))

And my other question is: What's the return value of called/lazy rules
if they have multiple target pattern elements? Only the first, or an
OrderedSet containing all of them? And do lazy rules allow for multiple
target pattern elements at all?

Thanks in advance,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: [ATL] Question about Called and Unique Lazy Rules [message #642433 is a reply to message #642431] Wed, 01 December 2010 10:31 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 522
Registered: July 2009
Senior Member
In a collection, you can bind either a single element or a list, both will work.

Lazy rules allow to build multiple elements but be careful that only the first will be returned.

If you need to catch more than one element, you should use a called rule instead of a lazy rule because in a called rule you explicitly specify the returned elements ex :

rule getCross(i: ecore!EObject) {
to
rel: metamodel!Relationship (
),
rel2 : metamodel!Relationship(
)
do{
-- here you specifiy the element(s) returned by the called rule
Sequence{rel,rel2};
}
}
Re: [ATL] Question about Called and Unique Lazy Rules [message #642443 is a reply to message #642433] Wed, 01 December 2010 11:13 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Sylvain EVEILLARD <s.eveillard@netfective.com> writes:

Hi Sylvain,

> In a collection, you can bind either a single element or a list, both
> will work.

Ah, nice. In the former case, is a collection created only when needed
(not already initialized)? To make the question clearer, consider that
example:

to foo : MM!Thing
do {
foo.refs <- thisModule.getSomeRefs(foo);
foo.refs <- thisModule.getOneRef(foo);
}

Does the second assignment insert the returned element into the refs
collection, or does a newly created collection with only the single
element replace the original value of the first assignment?

> Lazy rules allow to build multiple elements but be careful that only
> the first will be returned.

Thanks.

> If you need to catch more than one element, you should use a called
> rule instead of a lazy rule because in a called rule you explicitly
> specify the returned elements ex :
>
> rule getCross(i: ecore!EObject) {
> to
> rel: metamodel!Relationship (
> ),
> rel2 : metamodel!Relationship(
> )
> do{
> -- here you specifiy the element(s) returned by the called rule
> Sequence{rel,rel2};
> }
> }

Ah, that's kinda nice. But the User Guide states that inside the
imperative code section only a sequence of statements is allowed. So is
the principle that a called rule rule usually returns the value of the
first target pattern variable, unless the imperative code section's last
statement is an expression. In that case, the value of the expression
is returned.

Bye,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: [ATL] Question about Called and Unique Lazy Rules [message #642461 is a reply to message #642431] Wed, 01 December 2010 13:04 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARD
Messages: 522
Registered: July 2009
Senior Member
Quote:
to foo : MM!Thing
do {
foo.refs <- thisModule.getSomeRefs(foo);
foo.refs <- thisModule.getOneRef(foo);
}

Does the second assignment insert the returned element into the refs
collection, or does a newly created collection with only the single
element replace the original value of the first assignment?

No, the element is added at the end of the collection so in the end the collection refs will contain the result of the getSomeRefs followed by the result of the getOneRef.

Quote:
Ah, that's kinda nice. But the User Guide states that inside the
imperative code section only a sequence of statements is allowed. So is
the principle that a called rule rule usually returns the value of the
first target pattern variable, unless the imperative code section's last
statement is an expression. In that case, the value of the expression
is returned.

In a called rule you ALWAYS have to specify what the rule returns even if it's only one element (unless it changed in the last ATL version).
Re: [ATL] Question about Called and Unique Lazy Rules [message #642478 is a reply to message #642461] Wed, 01 December 2010 13:45 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Sylvain EVEILLARD <s.eveillard@netfective.com> writes:

Hi Sylvain,

> Quote:
>> to foo : MM!Thing
>> do {
>> foo.refs <- thisModule.getSomeRefs(foo);
>> foo.refs <- thisModule.getOneRef(foo);
>> }
>>
>> Does the second assignment insert the returned element into the refs
>> collection, or does a newly created collection with only the single
>> element replace the original value of the first assignment?
>
> No, the element is added at the end of the collection so in the end
> the collection refs will contain the result of the getSomeRefs
> followed by the result of the getOneRef.

Oh, that's great.

> Quote:
>> Ah, that's kinda nice. But the User Guide states that inside the
>> imperative code section only a sequence of statements is allowed. So is
>> the principle that a called rule rule usually returns the value of the
>> first target pattern variable, unless the imperative code section's last
>> statement is an expression. In that case, the value of the expression
>> is returned.
>
> In a called rule you ALWAYS have to specify what the rule returns even
> if it's only one element (unless it changed in the last ATL version).

At least the current user guide at

http://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Language#Ca lled_Rules

says that in called rules, both "to" and "do" are optional. But indeed
you are right, and the docs are false. I've just tested it.

Thanks a lot!

Bye,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: [ATL] Question about Called and Unique Lazy Rules [message #642537 is a reply to message #642431] Wed, 01 December 2010 17:37 Go to previous messageGo to next message
Frédéric Jouault is currently offline Frédéric Jouault
Messages: 572
Registered: July 2009
Senior Member
Hi Tassilo,

If you use a given called rule in an expression, then it must return a value, and this value must be returned from the do block, which is non-optional *in this specific case*.

However, called rule do not need to return values: they may be called as statements from other do blocks. Therefore, the do block is indeed optional.


Best regards,

Frédéric
Re: [ATL] Question about Called and Unique Lazy Rules [message #642678 is a reply to message #642537] Thu, 02 December 2010 10:06 Go to previous message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Frédéric Jouault <frederic.jouault@univ-nantes.fr> writes:

Hi Frédéric,

> If you use a given called rule in an expression, then it must return a
> value, and this value must be returned from the do block, which is
> non-optional *in this specific case*.
>
> However, called rule do not need to return values: they may be called
> as statements from other do blocks. Therefore, the do block is indeed
> optional.

Ah, that makes it clear to me.

Thanks a lot!
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Previous Topic:[ATL] Refining Mode : Cannot create
Next Topic:[ATL] Do we have to instantiate ProfileApplication when transforming an extended model into another?
Goto Forum:
  


Current Time: Tue Sep 23 10:24:17 GMT 2014

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

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