This is pattern proposed to check a condition and make proper decision as if-then-else construct in other programming language
Sample code
\define truepart() Condition is met and it is true
\define falsepart() Condition is not met and it is false
Is x divisable by y?
|x: |<$edit-text tag=input tiddler=xTid default="" />|
|y: |<$edit-text tag=input tiddler=yTid default=""/>|
<$vars
x={{{ [[xTid]get[text]] }}}
y={{{[[yTid]get[text]]}}}>
<$list filter="[<x>remainder<y>match[0]then[truepart]else[falsepart]]" variable=ops>
<$macrocall $name=<<ops>> />
</$list>
</$vars>
- Create a new tiddler on tiddlywiki.com
- enter a value for x and a value for y in provided text box
- check the result (like x=10, y=2 --> r should be zero and then x=11, y=4 ----> r should be 1)
here a construct as below is used
<$list filter="[<condition>then[true]else[false]]" variable=ops>
If condition return a value then it is true else it is false
What do you think and do you recommend the above construct?
Tiddlywiki let you do things in several way, but it is important to use a good programming style here.
--Mohammad
Note: TW-Scripts offer several alternative but some are not easy to follow and understand.