Matthias Bohlen wrote:

Hi Chad,

Sunday, March 27, 2005, 6:08:17 PM, you wrote:

CB> Matthias Bohlen wrote:



Hi all,

when writing my own cartridge, I noticed again that macro argument
names are global, not local to the macro. This makes recursive
invocation of Velocity macros impossible...





Shouldn't we set velocimacro.context.localscope = true? The docs say
that this property controls whether reference access (set/get) within
a Velocimacro will change the context, or be of local scope in that
Velocimacro.



CB> Yeah we could set this in the velocity template engine. And re-run CB> the build and if everything builds we should be fine. My question CB> to you, is when you say it doesn't work...what do you mean?...what CB> happens? I'm using a recursive velocity macro in the hibernate CB> cartridge (see below), and things seem to work fine:

Your macro in the hibernate cartridge works because you do not use the
macro argument any more after the inner macro has been called.

Test this VTL code snippet here:

 #macro (MyMacro $argument)
 argument before: $argument
 #if ($argument < 5)
 #set ($x = $argument+1)
 #MyMacro($x)
 #end
 argument after: $argument
 #end

Invoke it with "#MyMacro(1)". You will get this output:

 argument before: 1
 argument before: 2
 argument before: 3
 argument before: 4
 argument before: 5
 argument after: 5
 argument after: 5
 argument after: 5
 argument after: 5
 argument after: 1

I would have expected:

 argument before: 1
 argument before: 2
 argument before: 3
 argument before: 4
 argument before: 5
 argument after: 5
 argument after: 4
 argument after: 3
 argument after: 2
 argument after: 1

The reason is that $argument is a global variable, not a variable that
is local to the macro. We should make it local because people might be
unaware of this fact and might be hunting template bugs for hours! :-)


Ok sounds definitely like its worth adding that property then :) I'll go ahead and add it after I release RC1 tonight.

Cheers...
Matthias

---

Matthias Bohlen
"Consulting that helps project teams to succeed..."

Internet:
  http://www.mbohlen.de/
  [EMAIL PROTECTED]

Phone: +49 (170) 772 8545








------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Andromda-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/andromda-devel

Reply via email to