Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » [ATL] Help with lazy rule(how to convert distinct-foreach to use lazy rule)
[ATL] Help with lazy rule [message #915668] Mon, 17 September 2012 18:06 Go to next message
lili Missing name is currently offline lili Missing nameFriend
Messages: 6
Registered: July 2011
Junior Member
Hello all,

I'm writing a module transformation and i have a rule using distinct foreach. The ATL editor informs that its deprecated. So i'm with some difficult to parse my rule to use a lazy rule instead foreach.

The scenery is something like this:

helper context Ma!Model def: reference(): Sequence (String) = self.externalReference.asSequence();

//externalReference is a multivalued field on Model (a list)
rule ma2 {
	from ma: Ma!Model
	
	to 
              mb1: Mb!Event (			

		references <- mb2,
                //the n relation between Event and ModInfo
		
		),
		
              mb2: distinct Mb!ModInfo foreach(e in ma.reference())(
			extReference <- e
              )
}



This way with foreach is working fine, but how to make the same thing with lazy rules?
I read the ATL manual but i couldn't make this work with a lazy rule
Can anyone help me with this?
Re: [ATL] Help with lazy rule [message #915843 is a reply to message #915668] Tue, 18 September 2012 04:16 Go to previous messageGo to next message
noi poi is currently offline noi poiFriend
Messages: 29
Registered: June 2012
Junior Member
Hey there!

Well i am new to ATL but i guess i can give you a little bit of lazy rule idea that i have got.

you see you need to make one rule and one lazy rule

rule ma2 {
from ma: Ma!Model

to
mb1: Mb!Event (

references <- ma.reference(),
//the n relation between Event and ModInfo

)
}
lazy rule 2
{ from reference : sequence(string)

mb2: Mb!ModInfo(
extReference <- reference()
)
}

Well the logic behind it is lazy rule 2 will be implicitly be called when you refer to reference in your rule ma2.

i got the idea of it from "Transforming Models with ATL1"
Frédéric Jouault, Ivan Kurtev . I think it might work
Re: [ATL] Help with lazy rule [message #915912 is a reply to message #915668] Tue, 18 September 2012 07:54 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 616
Registered: July 2009
Senior Member
Hello,

Lazy rules and their uses are simply illustrated from the ATL user guide: http://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Language#Lazy_Rules

In your case, you will have to replace the creation of the "mb2" model element (using a "distinct foreach" construct) by a call to a lazy rule (via the "collect" method) to set the "references" property of the "mb1" model element.

Note that "distinct foreach" is now deprecated and should not be used, it can always be replaced by a call to a lazy (declarative) rule.

Best regards,

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: [ATL] Help with lazy rule [message #916014 is a reply to message #915912] Tue, 18 September 2012 12:04 Go to previous message
lili Missing name is currently offline lili Missing nameFriend
Messages: 6
Registered: July 2011
Junior Member
Tanks so much for the answers. Now i think i got the point on the lazy rules. My mistake was the entrance for the lazy rule...I was tring the entrance like the common rules.. But expanded my research on this and i found this article that show how to refactor distinct-foreach www .jot.fm/issues/issue_2012_08/article2.pdf that toghether with noi_poi comment helped me to understand what i had to use as entrance for the lazy rule.
So i have now something like this:

helper context Ma!Model def: reference(): Sequence (String) = self.externalReference.asSequence();

//externalReference is a multivalued field on Model (a list)
rule ma2 {
	from ma: Ma!Model
	
	to 
              mb1: Mb!Event (			

		references <- ma.reference() -> collect (e |thisModule.references(e)),

		
		)
              )
}

lazy rule references{
      from reference : Sequence(String)

      to mb2: Mb!ModInfo(
		externalReference <- reference
	)
}


That works fine...thanks a lot!Problem solved!
Previous Topic:making a map of map
Next Topic:xmi:XMI root node to uml:Package root node
Goto Forum:
  


Current Time: Mon Dec 22 00:44:45 GMT 2014

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

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