Filtering a titlelist: Do field X and field Y match?

EDIT: This is a post where my own bad habit got in the way of remembering things that I used to know. :wink:

Read only if you want to entertain yourself. Otherwise skip to response by @saqimtiaz

In thinking through the puzzle thread, I realize that I wish I understood an easier way to get a simple filter run ā€” starting from a title list ā€” to filter out (or filter in, whatever) exactly those tiddlers where field X matches (or doesnā€™t match) field Y. The [get[fieldname]] step works conveniently enough for just one field at a timeā€¦ Of course we can work with variables, or nested lists, to get more ā€œelbow roomā€ for complex operations. But it seems like it should be intuitively easy to make a filter syntax that just handily compares one field against another. No?

In fact, I was able to construct a single long filter to do this (starting with title list and returning only the titles, or variants thereof, where key field fails to match text field), but it was terribly roundabout!

Boring details: Beginning with the title list, I used :map to tack one field value onto the end of the title string, then used :map again to backtrack to the title to retrieve the second field value to tack onto the end of the compound title stringā€¦(!) At that point the filter is carrying a string for each tiddler from the initial title list, modified to tack on suffixes for each of the field valuesā€¦ At which point a split-join-enlist combo can extract just the two field-values from the end of each string, and use a :filter-prefix run to evaluate (again for each of the initial titles in title-list) to keep only the strings with a discrepancy. Surely thereā€™s a better way?

Below is the gist of the single ā€” LONG! ā€” filter that accomplishes what I thought should be a simple task (testing whether there are any tiddlers, from the initial title list, where the two fields donā€™t match). Does TiddlyWiki have a better way of doing this within a single filter? (If not, could it be a worthy tweak?)

:[ā€¦initial filtered title list hereā€¦]
:map[<currentTiddler>get[key]addprefix[ā€”]addprefix<currentTiddler>] :map[<currentTiddler>split[ā€”]first[]join[]get[text]addprefix[ā€”]addprefix<currentTiddler>] :filter[<currentTiddler>split[ā€”]last[2]join[ ]enlist-input[]count[]compare:integer:eq[2]]" emptyMessage="SOLVED!"/>

Perhaps something along these lines?

[ā€¦initial filtered title list hereā€¦] :filter[{!!X}!match{!!Y}]

1 Like

'Doh

:crazy_face:

I must add more characters.

Thankyou!
:pray:

1 Like

Iā€™m not sure where or how I was working in a situation where I needed to stick to the [get[fieldvalue]] approach ā€” maybe because I was using a variable in a [get<feildvalue>] pattern. Somehow it then became a habit. :expressionless:

1 Like