You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Uday Kumar <ud...@eself.com> on 2001/07/13 04:58:58 UTC

Re: Can I write a macro that can call itself?

thank u very much....

-Uday


----- Original Message ----- 
From: "Brian Lloyd-Newberry" <ne...@yahoo.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, July 12, 2001 6:53 PM
Subject: Re: Can I write a macro that can call itself?


> --- Uday Kumar <ud...@eself.com> wrote:
> > "Can I write a macro that can call itself?"
> 
>    Yes. Recursion is possible in velocity. Here is a short demo that
> you can run to try it out. It really is pretty harmless, although I
> named the macro #forkBomb in honor of the many recursive nightmares
> some of us have had.
> 
>    On a seperate note those of you who run the code below will notice
> that there are line feeds that affect the presentation of the output.
> Is there a way to swallow a linefeed so that the macro code can be
> written on seperate lines?
> 
> -Brian
> 
> 
> Brian S. Lloyd-Newberry 
> newbeb@yahoo.com
> Vertical Learning Curve Solutions
> 
> 
> Example below
> ---------------------------------------------------------------------
> 
> #macro( indent $level )#foreach( i in [1..$level]) #end#end
> 
> #macro( forkBomb $level $max $inc )
> ##indent($level)Before Level: $level
> #if( $level && $level >= 0 && $level <= $max )
> #set( $level = $level + $inc )
> #indent($level)Before Fork: $level
> #forkBomb($level $max $inc)
> #indent($level)After Fork: $level
> #else
> #indent($level)No more forking at level: $level
> #end
> ##indent($level)After Level: $level
> #end
> 
> Try with 0 as level and 10 max
> #forkBomb(0 10 1)
> 
> Try with 5 as level and 10 max
> #forkBomb(5 10 1)
> 
> Try with 15 as level and 10 max
> #forkBomb(15 10 1)
> 
> Try with 10 as level and 10 max going downward
> #forkBomb(10 10 -1)
> 
> Try with 'hello' as level and 10 max
> #forkBomb('hello' 10 1)
> 
> ## Try with 0 as level and 100 max
> ## #forkBomb(0 100)
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>