currentValue for function

A follow-up question;

Consider this useful custom filter operator;

\function list.contains(list value then:"yes" else) [enlist<list>match<value>then<then>else<else>]

Using a $macrocall $name="list.contains" or <$transclude $variable="list.contains"

  • you can give the list as a list, field variable or empty
  • you can give a value to test if it is in the list.
  • By default it returns “then”, which is yes, or any other value given
  • If not found nothing is returned unless you set the else parameter.

All well and good. Now similar to the Original topic “currentValue for function”,

what if I wanted the default value to be returned equal to the value given?

In the above I could provide the same value to the value=“name” and then=“name” but is there any way I can reference the “current title” when it passes the test inside my custom operator?

  • I want to keep it as a function not a procedure. So cant use the parameters widget to compute the default value for then.

Is this the same as the “missing currentValue” ?

I don’t know enough to answer that, although I suspect that there’s no simple way to do this.

I don’t know if this was meant to be a very specific example to lead to this more general question:

or whether the list.contains was your specific goal.

If the latter, then I think there’s a simple enough answer.

You have a general-purpose function which can be used for all sorts of purposes. If you want one that has this other behavior, write a second function that simply calls this one. I don’t really understand the purpose of this second function, so I don’t have a good name for it, and will just call it list.contains2:

\function list.contains(list value then:"yes" else) [enlist<list>match<value>then<then>else<else>]
\function list.contains2(list value else) [list.contains<list>,<value>,<value>,<else>]

<$macrocall $name="list.contains2" list="Foo Bar Baz" value="Bar" else="no"/>

<$macrocall $name="list.contains2" list="Foo Bar Baz" value="Qux" else="no"/>

Will yield

Bar

no

This feels a lot cleaner than trying to handle the generic behavior and the more specific behavior in the same function.

Thanks @Scott_Sauyet for yours thoughts.

I like your redefinition approach I will give it some thought.

I am hoping there is an answer to;

The list.contains function is more a way to ask the question. Is there a way to get the “title” as it changes inside the function.

  • map and other filters runs can use current Tiddler and …current tiddler.