Auto clicker
Writing an auto clicker
Work goes on
and I still did not forget my site!
XHTML
Moved to XHTML 1.0 Transitional
Old news
You are browsing Home >Development >PPWizard >Recursion and PPW

Example: Recursion with PPWizard

On this site there is a seperate news page. Together with the small summary on every page it is generated automatically. Here I describe how I created the macros for it.
The entrys on the news page have been added with a macro. There is another macro which uses the same input to gernerate the summary.
An entry is added by using a macro as follows:
<$addnews Title="A new entry!"
Text="I'm not very creative at thinking up example texts.">
The macro $addnews is called with two parameters, the title and the text. The following macro generats the code for the news page from the parameters:
#(
#define newsadd
Title: {$title=''}<br />
{$text=''}
<hr>
#)
That way all entries are added.
Of course, we could just use this macro to generate the summary. The probelm I got then is that I couldn't control which entries would appear in the summary. To avoid this only the last three entries should appear in the summary.
The solution to this was to use two different $addnews macros. One is resposible for the news page, the other creates the summary. Both are located in different files.
Here is the macro for creating the summary:
1 #define newscount 0
2
3 #(
4 #define newsadd
5 #evaluate+ newscount <$newscount>+1
6 #evaluate ^news[newscount]^ \  
7 ^'{$title=! !}<br />{$text=! !}'^
8 #define+ newscont <$newsconthandler '3'>
9 #)
This macro is called every time an entry is added.
Explanation: the command in line 6 saves the text in the macro $news[newscount]. [newscount] is used to access the value of $newscount. That way $news1, $news2 etc are defined.
In line 9 the macro $newscont is (re)defined with $newsconthandler. The number (3 in this case) defines how many entries should appear in the summary. Here is what the $newsconthandler macro looks like:
#define newssubcount 0
#(
#define newsconthandler
#evaluate+ newssubcount <$newssubcount>+1
#ifdef news[newssubcount]
#if [<$newssubcount> <= {$#1}]
<$news[newssubcount]><$newsconthandler '{$#1}'>
#endif
#endif
#)
The macro calls itself maximaly three times. Every time it's called $newssubcount is increased by one. It stops calling itself if $newssubcount is bigger than three. Remember, the three was passed as the second paramter.
Every time the macro is called it adds $news[newssubcount] to the summary.

Conclusions

I just showed one out of many ways about solving the problem I had. I also think that there are ways that are faster and more efficient but here it's just a demonstration on reursive programming with PPWizard.
The idea of using recursions in PPWizard came when I wrote the menu. Now it is highly customisable and I only need to change a few line to change it.

Valid XHTML 1.0!Valid CSS!
Source: ppw_recur.it
Outfile: ppw_recur.en.html
Built: 2 Aug 2006 21:44:59
Last modified: Mon Jan 9 2006 at 5:16:08pm