velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Lloyd-Newberry <new...@yahoo.com>
Subject Re: Can I write a macro that can call itself?
Date Fri, 13 Jul 2001 01:53:04 GMT
--- Uday Kumar <uday@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/

Mime
View raw message