Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » where to define a variable?
where to define a variable? [message #968648] Fri, 02 November 2012 16:34 Go to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi there,


In an atl rule, where can i define a variable ?


I defined in "using block", but it looks like a constant.

using{
n:Integer=1;
}



Thanks
K
Re: where to define a variable? [message #971999 is a reply to message #968648] Mon, 05 November 2012 09:21 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

For variables which are local to a given rule, the "using" section is effectively the good option: http://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Language#Local_variables_section.
FYI, for variables global to a whole transformation, you should rather use helper attributes: http://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Language#Attributes.
However, by using the declarative constructs and OCL iterators instead, it could be very likely that you don't actually need such variables.

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: where to define a variable? [message #972418 is a reply to message #971999] Mon, 05 November 2012 16:05 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member
Hi Hugo,

Thanks a mil for your reply.

helper context source!DeviceItem def: getModules():
Sequence(source!ModuleItem)= self.ModuleList.ModuleItem->select(mi|mi.getSlotValue()<>'0')->sortedBy(mi|mi.getSlotValue().toInteger());

I defined following two integer variables and do block in a lazy rule and later changed in a for loop.

problem: I always get num as 0. Can you see the error?


using{
num:Integer=0;
index:Integer=1;
}

do{

for(m2 in a.getModules())
{
num = m2.getSlotValue().toInteger()-index;
if ( num<>0)
{
p.Modules<-thisModule.rule_getNullModule(m2);
}
else
{
p.Modules<-thisModule.rule_getModule(m2);
}
index = index+1;
}-- for all Modules

}--end do


Thanks.
K

[Updated on: Mon, 05 November 2012 16:25]

Report message to a moderator

Re: where to define a variable? [message #972498 is a reply to message #972418] Mon, 05 November 2012 17:20 Go to previous message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Variable (re)assignments in do sections have to performed using the <- operator and not the = one.

Best regards,

Hugo


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Previous Topic:ATL logic help
Next Topic:Problems to open a xmi file with Sample Reflective Ecore Model Editor
Goto Forum:
  


Current Time: Tue Apr 23 12:44:26 GMT 2024

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

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

Back to the top