Mat, Thank you! Well yes a dictionary tiddler can be used. I have used such a solution in my recent plugin Tamasha. I also implement the switch-case using your proposed solution. Really powerful.
By the way, there are situations where the operands are not constant. I just tried to see how I can implement a multi step IF. But I was not sure if my solution follows a good programming style or not! Best wishes Mohammad On Sun, Jan 24, 2021 at 6:10 PM Mat <[email protected]> wrote: > @Mohammad > > It is not the IF-THEN structure you're asking for but if the input and > output are predefined like that, then it'd be simpler to use a data tiddler > to just get the value i.e {{datatiddler##two}} ---> 2 > > <:-) > > On Sunday, January 24, 2021 at 11:24:58 AM UTC+1 Mohammad wrote: > >> I tried to implement the below pseudo code in TW 5.1.23 >> >> if x=one then >> print(1) >> elseif x=two then >> print(2) >> elseif x=three then >> print(3) >> else >> print(x is not valid) >> end >> >> with >> >> \define myfun(x) >> <$vars u={{{[<__x__>match[one]then[1]] [<__x__>match[two]then[2]] >> [<__x__>match[three]then[3]] +[addsuffix[ lili]] ~[<__x__>addsuffix[ is >> not valid]]}}} > >> This is u: <<u>> >> </$vars> >> \end >> >> It works fine on https://tiddlywiki.com/ by calling macro as below >> >> <<myfun one>> >> <<myfun two>> >> <<myfun three>> >> <<myfun four>> >> >> I wish to know is this a good practice in TW 5.1.23? If not what better >> solution do you propose? >> >> >> Best wishes >> Mohammad >> > -- > 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/ff7f5cc9-a710-4894-949a-b5e83b2788ecn%40googlegroups.com > <https://groups.google.com/d/msgid/tiddlywiki/ff7f5cc9-a710-4894-949a-b5e83b2788ecn%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/CAAV1gMDfUuM9Jn87MdHPV%3DHFNgtrpH3vSwMO6vX5ueDpiOm%3D-g%40mail.gmail.com.

