MOFM2T 1.1 RTF Avatar
  1. OMG Issue

MOFM2T11 — Example ambiguity

  • Key: MOFM2T11-8
  • Legacy Issue Number: 14438
  • Status: open  
  • Source: Obeo ( Laurent Goubet)
  • Summary:

    Section 8.1.5 describes initSections and tells us that

    ---------8<---------
    An InitSection contains a set of variable initializations to be used in the body of its owning block.
    --------->8---------

    Yet example A.3 sports something like this :

    ---------8<---------
    [template public class_header(c : Class)

    { int count = -1; }

    ]
    [...]
    [for(a : Attribute) | c.attribute)

    { count = count + 1; }

    ]
    #define [a.name/]_BIT [count/]
    [/for]
    --------->8---------

    First of all, "int count = 1" is syntactically wrong and should be "count : Integer = -1"; but I've raised this in a separate issue not accepted yet so I don't have its number). The real problem here is that this example initializes a variable "count" in the template's init section, then tries to -modify this variable in the init section of a for.

    That just cannot be with the specification as it is now : the second init section should be "count : Integer = count +1" to be syntactically correct, and this doesn't mean "increment the value of 'count'" but "create variable 'count' with value 'count + 1' so we actually create a second variable that hides the first. Furthermore, as this second variable is declared on a for, and initSection's variables are only meant to be useable in the 'for' body, this second "count" variable will only last for an iteration. This means that every iteration, we create a new variable 'count' of value '0' (since the first 'count' variable is '-1').

    There is nothing in MOFM2T that's been specified as something that allows for the modification of a variable. We can only initialize them. Modifying variables requires the introduction of a non-generating block. Side-effect free blocks where we could do things without generating text.

    The next version should revise the A.3 example so as not to be misleading about the signification of InitSections. It should also introduce a new block dedicated to logic.

  • Reported: MOFM2T 1.0 — Mon, 28 Sep 2009 04:00 GMT
  • Updated: Fri, 6 Mar 2015 20:58 GMT