| 
| [ATL] Writing to helpers in model element context [message #65726] | Sun, 04 November 2007 06:30  |  | 
| Eclipse User  |  |  |  |  | Hi. 
 Recently I tried to define attributes (non-functional helpers) in the
 context of a model element and then writing to them, but with no success.
 
 I define the helper with code like this:
 
 helper context Metamodel!Element def: attr : Integer = 0;
 
 However, if I try to set the attribute with imperative code like...
 
 foreach (el in Metamodel!Element.allInstances())
 {
 el.attr <- 1;
 }
 
 .... execution fails with error "GRAVE: message: feature attr does not exist
 on Metamodel!Element".
 In case it matters, I tried setting attributes both in the entrypoint rule
 and in rules called by matched rules.
 
 This happens only with attributes having context. I can work around the
 problem by using module-level attributes instead, using a Map type to
 associate values with elements, but I'm not liking it because the code
 becomes bloated.
 
 Is this a bug or am I missing something?
 Thanks.
 
 --
 Lorenzo
 |  |  |  | 
| 
| Re: [ATL] Writing to helpers in model element context [message #65751 is a reply to message #65726] | Mon, 05 November 2007 03:33   |  | 
| Eclipse User  |  |  |  |  | Originally posted by: mddfabro.ilog.fr 
 Hello,
 
 attribute helpers are side-effect free, which means they can be used
 only to get/calculate values.
 
 So, the solution to set up values is to use a Map as you did.
 
 Regards,
 
 Marcos.
 
 Lorenzo Dalla Vecchia wrote:
 > Hi.
 >
 > Recently I tried to define attributes (non-functional helpers) in the
 > context of a model element and then writing to them, but with no success.
 >
 > I define the helper with code like this:
 >
 >    helper context Metamodel!Element def: attr : Integer = 0;
 >
 > However, if I try to set the attribute with imperative code like...
 >
 >    foreach (el in Metamodel!Element.allInstances())
 >    {
 >        el.attr <- 1;
 >    }
 >
 > ... execution fails with error "GRAVE: message: feature attr does not
 > exist on Metamodel!Element".
 > In case it matters, I tried setting attributes both in the entrypoint
 > rule and in rules called by matched rules.
 >
 > This happens only with attributes having context. I can work around the
 > problem by using module-level attributes instead, using a Map type to
 > associate values with elements, but I'm not liking it because the code
 > becomes bloated.
 >
 > Is this a bug or am I missing something?
 > Thanks.
 >
 > --
 > Lorenzo
 |  |  |  | 
| 
| Re: [ATL] Writing to helpers in model element context [message #66831 is a reply to message #65751] | Mon, 26 November 2007 22:32  |  | 
| Eclipse User  |  |  |  |  | Hello, 
 Here are some precisions: context-less attribute helpers ("helper def:")
 can be set form imperative code. Other attribute helpers ("helper
 context MM!CC def:) cannot be set, only queried.
 
 As Marcos said, the reason is that there are declarative, and
 side-effect free. However, it should be possible to implement the
 behavior your describe when attribute values are cached. If this is not
 the case, then a special case could be added: first check if in cache,
 else compute value but do not put in cache.
 
 However, I am not sure implementing this feature would be a step in the
 "right" (i.e., declarative ;-)) direction.
 
 
 Regards,
 
 Frédéric Jouault
 
 
 Marcos Didonet Del Fabro wrote:
 > Hello,
 >
 > attribute helpers are side-effect free, which means they can be used
 > only to get/calculate values.
 >
 > So, the solution to set up values is to use a Map as you did.
 >
 > Regards,
 >
 > Marcos.
 >
 > Lorenzo Dalla Vecchia wrote:
 >> Hi.
 >>
 >> Recently I tried to define attributes (non-functional helpers) in the
 >> context of a model element and then writing to them, but with no success.
 >>
 >> I define the helper with code like this:
 >>
 >>    helper context Metamodel!Element def: attr : Integer = 0;
 >>
 >> However, if I try to set the attribute with imperative code like...
 >>
 >>    foreach (el in Metamodel!Element.allInstances())
 >>    {
 >>        el.attr <- 1;
 >>    }
 >>
 >> ... execution fails with error "GRAVE: message: feature attr does not
 >> exist on Metamodel!Element".
 >> In case it matters, I tried setting attributes both in the entrypoint
 >> rule and in rules called by matched rules.
 >>
 >> This happens only with attributes having context. I can work around
 >> the problem by using module-level attributes instead, using a Map type
 >> to associate values with elements, but I'm not liking it because the
 >> code becomes bloated.
 >>
 >> Is this a bug or am I missing something?
 >> Thanks.
 >>
 >> --
 >> Lorenzo
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.44754 seconds