Hi Xavier, Tony, thanks that looks very helpful I'm going to study that and have some fun !
Cheers Eric On Thursday, May 21, 2020 at 3:47:30 AM UTC+4, TonyM wrote: > > Eric > > The first quick tip about recursive processes in tiddlywiki is if a filter > is used to call a level it usually describes a list of titles or values > which are themselves limited in number, that is they are exhausted > eventually and the recursive process returns to the previous call. > > here is an example I shared sometime ago, intentionally made into two > macros so the user can find where to insert modifications > > \define each-other-level(filter) > <li><$link to=<<currentTiddler>> ><$text > text=<<currentTiddler>>/></$link></li> > <ul> > <$list filter="$filter$"> > <<each-other-level $filter$>> > </$list> > </ul> > \end > \define first-level(filter) > <ul> > <$list filter="$filter$"> > <<each-other-level $filter$>> > </$list> > </ul> > \end > > Start in TableOfContents<br> > <$tiddler tiddler="TableOfContents"> > > <<first-level "[is[current]tagging[]]">> > > </$tiddler> > > > Although quite complex one insight for the adventerouse into recursive > processes in tiddlywiki is the TOC macros which obviously use recursion > see $:/core/macros/toc > > Of course if you iterate a hierarchy you need to be careful of entering an > infinite loop if one item has a child that is above it in the hierarchy "it > may be its own grandfather". > > Bimlases Kin filter is good at turning hierarchies into a flat list of > titles (among other things) so this can simplify code. > > I think using filters can make recursion easy in TiddlyWiki because it > naturally limits the iterations, but if you look in my example above, in > each-other-level you could add logic to skip calling itself in particular > conditions. > > Regards > Tony > > > > On Wednesday, May 20, 2020 at 7:01:17 PM UTC+10, Eric N. wrote: >> >> Hi Tony, >> Sorry for the late answer... >> >> You are right, I am sometimes confusing this google group with a >> Tiddlywiki FAQ + code review + ideas box + many other things ;-) >> >> My main question was not really about how to solve my specific problem, >> but the generic problem of using recursive macros and if then else nested >> statements in the macros. >> >> I'm used to using functions, and in those a simple "return value" will >> skip the rest of the function code. Clear and short code. >> >> In macros, I'll display the output "value" but then I have to make sure >> that the rest of the code is not executed, i.e. that it doesn't display and >> execute other stuff. That is, I need to make sure that I'll reach the >> "\end" of the macro without executing anything - as if I did return a value >> in a function. >> >> Because of this "as if", i.e. because I have to make sure I'll reach the >> end of the macro code without executing anything once I've output what I >> wanted, I have to use a lot of if then else statements, nested, i.e. a lot >> of "<$list filter=...>" statements. >> >> And because of that, the code I write seems to me hard to read, hard to >> understand later on and hard to maintain. (cf nested lists in my original >> post) >> >> And so, this is so surprising to me that I end up with a code I am not >> comfortable with, not happy with, that I wondered if there was something I >> completely missed with macros and nested if-then-else statements. >> >> >> If that's just the way it works, then OK... Otherwise I'd be happy to >> learn how to produce a better code :) >> >> Best, >> And have a good day everyone ! >> >> >> Eric >> >> >> On Thursday, May 14, 2020 at 3:38:20 PM UTC+4, TonyM wrote: >>> >>> Eric >>> >>> Love the way you are thinking some of us have done similar things. I >>> think it is as easy as anywhere to do this kind of thing. Of course it has >>> its own complexity. I would look at solving component issues then bring >>> them together in a solution. >>> >>> I can help more later but consider a custom new here button which passes >>> more to the child tiddler than a tag. Its easy to creat a tiddler with >>> additional fields. I have posted on setting context before but a simple >>> fieldname={{!!fieldname}} in the creat tiddler can do a lot. >>> >>> I will see what other tips I can share when next at my desktop. >>> >>> Regards >>> Tony >>> >>> -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/eb3dbef8-dd46-41c8-8b85-983b3ebe7188%40googlegroups.com.