switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
\define items() One Two [[Three Four]] Five
\define switch(item)<$list filter="[enlist<items>search<__item__>]" emptyMessage="Zero"><<currentTiddler>></$list>\end
<<switch One>><<switch "Three Four">><<switch "Ten">>
<$list filter="[enlist<items>search<__item__>]" emptyMessage="Zero">
<$list filter="[enlist<items>title<__item__>]" emptyMessage="Zero">
"Case" is a common programming structure although it can get quite sophisticated. I went thru a process of building ways to build methods for all the basic programming structures in tiddlywiki more than a year ago. I will see what I can dig up.
Tony
\define switch(item, list:"a b c")<$list filter="[enlist<__list__>search<__item__>]" emptyMessage="Default">You passed <<currentTiddler>></$list>\end
<<switch a>>
<<switch b>>
\define a() This is the action for a.\define b() This is action for b.\define c() This is action for c.\define default() This is default action.
\define switch(item, list:"a b c")<$list filter="[enlist<__list__>search<__item__>]" emptyMessage=<<default>> variable="actMacro"><$macrocall $name=<<actMacro>> /></$list>\end
<<switch a>>
<<switch b>>
<<switch d>>
--
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+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/b5fb6465-db3a-4809-a878-5b475f3c1b99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi MohammadYour construction with list widgets is a pretty good approximation of a switch/case construction. The only frustration is that it is possible for a value to trigger more than one of the list widgets; it would be better if there was a way to make things stop after the first match.One could certainly imagine a <$switch>/<$case> widget pair that could resolve that issue and might be more efficient as well. Perhaps after v5.1.20Best wishesJeremy
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.