title: Velocity: Is it possible to nest macros that use #@ and $bodyContent?
body: <p>I have a macro that looks essentially like this:</p>
  
  <pre><code>#macro( surround $x )
    surround:$x
      $bodyContent
    /surround:$x
  #end
  </code></pre>
  
  <p>Invocation <code>#@surround("A")bunch o' stuff#end</code> produces "surround:A bunch o' stuff /surround:A" as
  expected. Invocation <code>#@surround("A")#@surround("B")more stuff#end#end</code> produces
  surround:A surround:B more stuff /surround:B /surround:A which is exactly what I want.</p>
  
  <p>But now I want to build upwards with another macro</p>
  
  <pre><code>#macro( annotated-surround $x $y )
    #@surround( $x )
      annotate:$y
      $bodyContent
    #end
  #end
  </code></pre>
  
  <p>The intended expansion of <code>#annotated-surround( "C" "note" ) stuff #end</code> is
      surround:C annotate:note stuff /surround:C</p>
  
  <p>...but this doesn't work; I get the dreaded semi-infinite expansion of the annotated-surround body
  content.</p>
  
  <p>I have read the answer at <a href="https://stackoverflow.com/questions/12519289/closure-in-velocity-template-macros">Closure in Velocity template macros</a> and still don't quite know whether what I want to do is possible.</p>
  
  <p>I'm willing to do arbitrarily tricky things within the definitions of <code>#surround</code> and
  <code>#annotated-surround</code>, but I don't want the users of those macros to see any complexity. The
  whole idea is to simplify their lives.</p>
  
  <p>As long as I have your ear: Setting <code>macro.provide.scope.control=true</code> is supposed to "a local namespace in macros". What does this mean? Is the provided namespace independent of the default context, but with a single such space shared among all invocations of all macros? Or is a separate context provided for each macro invocation, even recursively? It has to be the latter because of <code>$macro.parent</code>, right?</p>
  
  <p>And yet another question. Consider the following macro:</p>
  
  <pre><code>#macro( recursive $x )
    #if($x == 0)
      zero
    #else
      $x before . . . 
      #set($xMinusOne = $x - 1)
      #recursive($xMinusOne)
      . . . $x after
    #end
  #end
  </code></pre>
  
  <p><code>#recursive( 4 )</code> yields:</p>
  
  <p>4 before . . .
  3 before . . .
  2 before . . .
  1 before . . .
  zero . . .
  0 after . . .
  0 after . . .
  0 after . . .
  4 after</p>
  
  <p>Now I understand all those occurrences of "0": there's only one global $x, so assigning to it on
  the recursive calls smashes it and it doesn't get restored. But where on earth does that final "4"
  come from? For that matter, how is it that my first "surround" macro works to arbitrary depth;
  how come its final $x doesn't get smashed in inner calls?</p>
  
  <p>Sorry to be so prolix, but I have been unable to find clear documentation in this matter.</p>