Jeremy recently added a new fiter rub prefix to TiddlyWiki Filter Language. See
He stated that:
This PR introduces a new filter run prefix
:letthat assigns the result of the filter run to a variable that is made available for the remaining filter runs of the filter expression.It solves the problem that otherwise it is impossible to compute values for filter operator parameters; parameters can only be a literal string, text reference or variable reference. The
:letfilter run prefix provides a solution:[my.custom.function<param>,[2]] :let[[index]] [<data>jsonget[top],<index>]The shortcut syntax
=>can also be used:[my.custom.function<param>,[2]] =>index [<data>jsonget[top],<index>]Using the shortcut syntax also avoids having to use double square brackets around the name of the variable.
This example first sorts all the input tiddlers by length, and then uses the length of the shortest title as the second index of a JSON lookup:
[all[tiddlers]] :sort:number[get[text]length[]] :let[[index]] [<data>jsonget[top],<index>]This PR also introduces the ability for multi-valued variables which contain list of results, not just single strings. They can be assigned with the new
:letfilter run prefix, or the existing<$let>widget. The full list of values can be retrieved using round brackets instead of the usual angle brackets. In all other contexts only the first item in the list is used as the variable value.
This seems exciting. You can evaluate this new feature on TiddlyWiki Pre-release ā 5.4.0-prerelease
See also official doc: https://tiddlywiki.com/prerelease/#Let%20Filter%20Run%20Prefix
My question is: Can you give some simple examples can be use by an intermediate TW user?
Examples
These examples are tested on TiddlyWiki Pre-release ā 5.4.0-prerelease
Eaxample 01
<$let diff= {{{ [tag[Learning]get[text]length[]sum[]] :let[[smL]]
[tag[HelloThere]get[text]length[]sum[]] :let[[smH]]
[<smL>subtract<smH>]
}}} >
The difference is: <<diff>>
</$let>
Produces: The difference is: 49437. Here the smL and smH are two variables store intermediate results.
Example 02
You may open TiddlyWiki Pre-release ā 5.4.0-prerelease and create few tiddlers tagged with idea. There are some tiddlers with task tag.
<$let mood = {{{
[tag[task]count[]] :let[[numTasks]]
[tag[idea]count[]] :let[[numIdeas]]
[<numTasks>subtract<numIdeas>] :let[[diff]]
[<diff>match[0]then[[Balanced mindset]]
[<diff>compare:integer:gt[0]then[Youāre actionāoriented]]
[<diff>compare:integer:lt[0]then[Youāre in a creative phase]]
}}}>
<p>Your current mood: <<mood>></p>
</$let>
Produces: Your current mood: Youāre actionāoriented
Example 03
<$let weekendMessage={{{
[<now>format:date[DDD]] :let[[today]]
[<today>match[Saturday]then[Go for shopping!]]
[<today>match[Sunday]then[Go for exercise!]]
:else[[Keep focused, itās a weekday.]]
}}}>
Today is: ''<<now format:"DDD">>''<br/>
Message: ''<<weekendMessage>>''
</$let>
Produces:
Today is: Thursday
Message: Keep focused, itās a weekday.





