Wikitext version of switch/nested if-else/nested ternary statements

As per @etardiff simple approach before you can use a procedure to contain the name/icons and also use a function within it to generate a text only icon.

  • This is a procedure and can be used as a macro
\procedure result-symbol(fieldname:won)
   \define yes() ✅
   \define no() ❌
   \define pending() ◎
   \function get.symbol() [all[current]get<fieldname>getvariable[]]
  <<get.symbol>>
\end result-symbol

<<result-symbol>>
  • This acts on the current tiddler so if it is the candidacy tiddler, or inside a list widget will work.
  • This also allows you to provide a different fieldname with won the default

Note:

I and others have pointed out some delayed rendering of functions after a change, I need to close and open, the tiddler or preview, sometimes to see a change.

  • This has made this work fiddly at times and sometimes a change is not reflected eg; if the won field changes, unless the tiddler is refreshed.
  • This needs fixing.

Alternatively if you want to use it in a filter or as a filter operator you can ditch the procedure

   \define yes() ✅
   \define no() ❌
   \define pending() ◎
   \function get.symbol(fieldname:won) [all[current]get<fieldname>getvariable[]]
 

<<get.symbol>> on the current tiddler
{{{ [<candidacy>get.symbol[]] }}}

Not intentionally. :frowning_face: I thought I was passing the result of calling that function. Among the variations I tried was [lookup.in[election-symbols],[<candidacy>get[won]]], but that is a filter syntax error, for a reason I don’t yet understand. (I’m not asking. I will spend some time on it later this week, but that should demonstrate what I thought I was doing.) This definitely explains the problems I’ve been having.

Thank you very much. That is what I was looking for. A big fan of functional programming, I reach for map all the time, and not just for lists. But I don’t yet have the habit of using it in this way, as almost a syntactic punctuation to separate the function application from another expression. It makes sense, but I need to retrain my brain a little to see it this way.

Thank you for the response. This one was really bugging me!

Thank you. I will probably combine @etardiff’s approach with your suggestion of using a JSON string rather than a JSON tiddler. But seeing how many useful variants there are is extremely helpful.

I agree that this should be fixed. I haven’t run across it yet, but will try to keep my eye out for it.

I’ve been trying to learn my way into the core, having worked on several changes more on the periphery. This might be a good thing for me to take up, although there’s a strong chance that it’s too far beyond my current knowledge. (This thread demonstrates that my understanding of TW \functions is still fairly weak.) I don’t know if I’ll have time soon, but if I do, I might try to take this on. Do you know if there is already a GitHub issue for it?

1 Like

Me, too. It’s very hard to pin down where/why/(who). I thought it was me (usually is, it’s all about me, didn’t you know?), because I’ve been faffing around with stacks and window[“vars”] (globalThis? :shushing_face: ).

Perhaps there’s an overly zealous/eager optimisation in the core somewhere?

I think I’m good now – with help from @EricShulman’s timeout plugin (thanks Eric) I managed to force the update to happen (focus away, focus back in ~2x20ms).

1 Like

That sounds like a bug that has already been fixed for v5.3.2. It would be helpful if you could test https://tiddlywiki.com/prerelease

1 Like

A quick test where I update a field in edit mode, that is used as input to a custom operator is working well.

  • I will need a little more time to identify the cases that were causing problems because it was somewhat fragile.

But it is looking good thanks.

I am not exactly sure what this means;

This is currently just a failing test for #7696