Unsure about behaviour of currentTiddler and ..currentTiddler when used inside functions called within prefixed filter runs or subfilters

Hello

I’ve been playing around with using functions at various levels, and I came across some behaviour which I’m not sure about - it could be intended, or it could be a bug, or there could just be something I’m missing.

From what I can tell, if a function definition uses the currentTiddler variable, and then that function is invoked in an environment where there would normally be a temporarily different currentTiddler and the existing currentTiddler would become ..currentTiddler (e.g. inside filter runs with the map prefix, or within subfilters), the function seems to ignore this reassignment and return ..currentTiddler when you call currentTiddler, and nothing when you call ..currentTiddler.

See example code below:

\function .returnCurrent() [<currentTiddler>!is[blank]else[NA]]
\function .return..Current() [<..currentTiddler>!is[blank]else[NA]]

<$tiddler tiddler="outer">

testing functions in "outer" tiddler:
<<.returnCurrent>>
<<.return..Current>>

testing function inside map prefix:
{{{ inner :map[<.returnCurrent>] }}}
{{{ inner :map[<.return..Current>] }}}

testing subfilter:
<$let subfilter="""[<.returnCurrent>] [<.return..Current>]""">
{{{ [[inner]subfilter<subfilter>] }}}
</$let>

</$tiddler>

All three of these tests seem to return the sequence “Outer NA” for me, despite the fact that I would expect the 2nd and 3rd tests to return “Inner Outer” instead.

Does anyone know if this is intended behaviour, or if there is something I’m missing here?

Thanks for reading

Hi @exilegreen, this is a known bug that will be fixed in next release. See fixes functions to use variables set by filter runs by saqimtiaz · Pull Request #7906 · Jermolene/TiddlyWiki5 · GitHub

You can test your code in the demo wiki with the fix in it:
https://tiddlywiki5-8jp45lsqq-jermolene.vercel.app/

This bug was also reported here: Function Idiosyncrasy: Bug or Feature?

2 Likes

Ah, amazing. Thank you for pointing me to that. :slight_smile: