Ok, So I have played with the idea of “case structures” in tiddlywiki and as I suspected it really depends on what you want to achieve, display something, return something, transclude something, deal with else cases, return only one value etc…
I can see us documenting a range of case structures without necessarily developing a separate widget, in part because it would be hard to write one that can cater for the large number of possible uses. Here is a simple example;
\define case(input:"d")
<$set name=input filter="[[$input$]uppercase[]]">
<$list filter="[<input>match[A]then[Another]]" template="true"></$list>
<$list filter="[<input>match[B]then[Best]]" template="true"></$list>
<$list filter="[<input>match[C]then[Caught]]" template="true"></$list>
<$list filter="[<input>match[D]then[Default]]" template="true"></$list>
\end
<<case "A">>
Where “true” is a tiddler that displays the current tiddler.
- The condition ensures one and only one value is returned
- However every test is made, with a nestable if-then-else structure this could be designed better.
- To use the result of
<<case "A">>
other than to display, it must be wikified/evaluated.
I can already imagine a dozen ways to do this, the question is how do we focus on the idea of a Generic Case Statement?