velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plynch...@netscape.net
Subject RE: Recursion
Date Thu, 08 Aug 2002 16:40:57 GMT
So far I haven't had to do anything recursive.  But how about if you
modify the macro so that it takes an ArrayList and operates on the
last element in the list.  Something like:

#macro( processNode $nodeList )
#set($node = $nodeList.get($nodeList.size()-1))
<item>
  <text>$node.text</text>
  #foreach( $child in $nodeList.get($nodeList.size()-1).children )
     $nodeList.add($child)
     #processNode( $nodeList )
     $nodeList.remove($nodeList.size()-1)
  #end
</item>
#end

Note that after the call to #processNode, $child will probably set
to something different.  In the code above, that should be okay,
it gets set to something else in the foreach right away.  Also, $node
will probably be set to something else, so don't use it after calling
#processNode.

I haven't tested this, so it might not be quite right, but hopefully
it will give you a direction to try in.

   --Paul

Adam Esterline <AdamE@cait.wustl.edu> wrote:

>You are correct.   That is not what I want, but how do I work around it.
>
>Adam
>
>-----Original Message-----
>From: plynchnlm@netscape.net [mailto:plynchnlm@netscape.net]
>Sent: Thursday, August 08, 2002 9:57 AM
>To: velocity-user@jakarta.apache.org
>Subject: RE: Recursion
>
>
>The Velocity documentation says that macro parameters are passed "by
>name".  I think this means that if you called #processNode($a), the code
>that would be run would be:
>
><item>
>   <text>$a.text</text>
>   #foreach( $child in $a.children )
>      #processNode( $child )
>   #end
></item>
>
>But, when the recursive part starts, $child is passed as an argument,
>so would you would get (I think) is this:
>
><item>
>   <text>$child.text</text>
>   #foreach( $child in $child.children )
>      #processNode( $child )
>   #end
></item>
>
>which is almost certainly not what you wanted.
>
>  --Paul
>
>
>Adam Esterline <AdamE@cait.wustl.edu> wrote:
>
>>No.   That still did not work.
>>
>>Adam
>>
>>-----Original Message-----
>>From: lloyd [mailto:subscr001@twilight-systems.com]
>>Sent: Wednesday, August 07, 2002 6:12 PM
>>To: Velocity Users List
>>Subject: Re: Recursion
>>
>>
>>Adam Esterline wrote:
>>> I have seen several posts about this issue, but I still don't understand.
>>> Here is my example, could someone please explain why this does not work.
>>>
>>>
>>> ## Macro for creating the outline XML
>>> #macro( processNode $node )
>>> <item>
>>>    <text>$node.text</text>
>>>    #foreach( $child in $node.children )
>>>       #processNode( $child )
>>>    #end
>>> </item>
>>> #end
>>
>>
>>Wild guess:
>>
>>Have you tried getting a reference to children first:
>>
>>#(set $childNodes = $node.children )
>>#foreach( $child in $childNodes )
>>...etc
>>
>>?
>>
>>
>>--
>>To unsubscribe, e-mail:
>><mailto:velocity-user-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail:
>><mailto:velocity-user-help@jakarta.apache.org>
>>
>>--
>>To unsubscribe, e-mail:  
><mailto:velocity-user-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail:
><mailto:velocity-user-help@jakarta.apache.org>
>>
>>
>
>
>__________________________________________________________________
>Your favorite stores, helpful shopping tools and great gift ideas.
>Experience the convenience of buying online with Shop@Netscape!
>http://shopnow.netscape.com/
>
>Get your own FREE, personal Netscape Mail account today at
>http://webmail.netscape.com/
>
>
>--
>To unsubscribe, e-mail:
><mailto:velocity-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail:
><mailto:velocity-user-help@jakarta.apache.org>
>
>--
>To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>
>
>


__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience
of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


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


Mime
View raw message