Hi Eric,
One TW5 feature that helps a lot with recursions is the *emptyMessage*
attribute of the $list widget. If you put your default values there, you
often can manage to put your recursive calls inside a single list. Another
feature that helps you keep a compact code while computing conditional
values, is the ability to use filters inside {{{}}}. For instance:
\define get_recursive_field(note_title, field_name:"me_agree")
<$list
*filter="[<__note_title__>!is[missing]!subfilter<source-match>!has<__field_name__>]"
*
*emptyMessage="""<$text text={{{
[<__note_title__>get<__field_name__>] ~[[can't find any value for
]addsuffix<__field_name__>] }}}/>""*">
<$vars heading={{{ [<__note_title__>tags[]subfilter<note-match>]
~[<__note_title__>tags[]subfilter<source-match>] }}}>
Per <$link to=<<heading>>><<heading>></$link> =>
<$macrocall $name="get_recursive_field" note_title=<<heading>> />
</$vars>
</$list>
\end
<$vars source-match="[prefix[so]]" note-match="[prefix[no]]">
<$macrocall $name="get_recursive_field" note_title=<<currentTiddler>>/>
</$vars>
Cheers,
-- Xavier
On Wed, May 20, 2020 at 11:01 AM Eric N. <[email protected]> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tiddlywiki/6e270145-48cb-4e8b-88e5-df5226cb360a%40googlegroups.com
> <https://groups.google.com/d/msgid/tiddlywiki/6e270145-48cb-4e8b-88e5-df5226cb360a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/CADeSwYPcQONs4RBf0ywGnNd83y9%3DAtRVq_8wh%2BA%2BXMmc8Tyj9A%40mail.gmail.com.