You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jean-Marc Reynaud <JR...@rdfgroup.com> on 2006/03/08 17:12:51 UTC

#macro recursion

Is it possible for #macro()s to recurse?

 

I'm attempting recursion but the output is not as expected and I'm not
sure whether it's due to my code or whether recursion is not supported.

 

 

Kindest regards,

 

Jean-Marc Reynaud

 


This transmission is confidential and intended solely for the person or organisation to whom it is addressed. It may contain privileged and confidential information. If you are not the intended recipient, you should not copy, distribute or take any action in reliance on it. If you have received this transmission in error, please notify the sender immediately. Any opinions or advice contained in this e-mail are those of the individual sender except where they are stated to be the views of RDF Group plc. All messages passing through this gateway are virus scanned.


Re: #macro recursion

Posted by ap...@recks.org.
Macro recursion works, but beware that velocity passes 
parameters as references to the original context - which
means that changing this variable within the macro 
changes it for the caller.

So recurse with depth first is tricky or imposible:
#macro( myMacro $foo )
  #myMacro( $foo + 1 )
  ... ## do something with $foo cannot work
#end

So you need to do:
#macro( myMacro $foo )
  #set( $bar = $foo )## dereference $foo
  ... ## use $bar here
  #myMacro( $bar + 1 )## recurse depth last
#end

Or use the #local directive (see the contrib area or wiki, 
and please check the exact usage syntax - I'm writing
out of my rememberabnce):
#macro( myMacro $foo )
  #local( $bar )
  #set( $bar = $foo )## dereference $foo
  #myMacro( $bar + 1 )## recurse depth first
  ... ## use $bar here
  #end
#end

I've used recursion once, and hope this knowhow helps.

Cheers,
Christoph

> Von: "Will Glass-Husain" <wg...@forio.com>
> An: "Velocity Users List" <ve...@jakarta.apache.org>
> Betreff: Re: #macro recursion
> Datum: Wed, 8 Mar 2006 09:01:00 -0800
> 
> Yes, but their are some pecularities about scoping.
> 
> Do you have this property set to true?
> velocimacro.context.localscope
> 
> I'm not experienced in Macro recursion, but I suggest you try that.  Maybe
> someone else would chime in who works with recursion macros.  Or check the
> archives.  (the topic has come up before).
> 
> WILL
> 
> 
> On 3/8/06, Jean-Marc Reynaud <JR...@rdfgroup.com> wrote:
> >
> > Is it possible for #macro()s to recurse?
> >
> >
> >
> > I'm attempting recursion but the output is not as expected and I'm not
> > sure whether it's due to my code or whether recursion is not supported.
> >
> >
> >
> >
> >
> > Kindest regards,
> >
> >
> >
> > Jean-Marc Reynaud
> >
> >
> >
> >
> > This transmission is confidential and intended solely for the person or
> > organisation to whom it is addressed. It may contain privileged and
> > confidential information. If you are not the intended recipient, you
> should
> > not copy, distribute or take any action in reliance on it. If you have
> > received this transmission in error, please notify the sender
> immediately.
> > Any opinions or advice contained in this e-mail are those of the
> individual
> > sender except where they are stated to be the views of RDF Group plc.
> All
> > messages passing through this gateway are virus scanned.
> >
> >
> >
> 
> 
> --
> Forio Business Simulations
> 
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: #macro recursion

Posted by Will Glass-Husain <wg...@forio.com>.
Yes, but their are some pecularities about scoping.

Do you have this property set to true?
velocimacro.context.localscope

I'm not experienced in Macro recursion, but I suggest you try that.  Maybe
someone else would chime in who works with recursion macros.  Or check the
archives.  (the topic has come up before).

WILL


On 3/8/06, Jean-Marc Reynaud <JR...@rdfgroup.com> wrote:
>
> Is it possible for #macro()s to recurse?
>
>
>
> I'm attempting recursion but the output is not as expected and I'm not
> sure whether it's due to my code or whether recursion is not supported.
>
>
>
>
>
> Kindest regards,
>
>
>
> Jean-Marc Reynaud
>
>
>
>
> This transmission is confidential and intended solely for the person or
> organisation to whom it is addressed. It may contain privileged and
> confidential information. If you are not the intended recipient, you should
> not copy, distribute or take any action in reliance on it. If you have
> received this transmission in error, please notify the sender immediately.
> Any opinions or advice contained in this e-mail are those of the individual
> sender except where they are stated to be the views of RDF Group plc. All
> messages passing through this gateway are virus scanned.
>
>
>


--
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com