Bug in contains operator?

For the contains operator, I was expecting the following to output the list (or at least to output something) but it yields naught:

<$set name=list filter="aaa bbb ccc">
{{{ [enlist<list>contains:title[aaa]] }}}
</$set>

Is there a bug or do I misunderstand someting?

What other solution is there to test if a title appears in a list? I am considering :intersection but it seems like overkill when one of the “lists” only has a single value, and also it would visually complexify to split up the filter into two.

I think you want ‘match’

https://tiddlywiki.com/static/match%20Operator.html

<$set name=list filter="aaa bbb ccc">
{{{ [enlist<list>match:title[aaa]] }}}
</$set>
1 Like

Ah, excellent! I now realise I have assumed that match needed to match its parameter with its whole input - but evidently I was wrong!

Thank you, that solves my needs!

I still don’t understnad why contains doesn’t work though!?

1 Like

No, your initial understanding was correct! {{{ [[aaa bbb ccc]match[aaa]] }}} wouldn’t produce anything, but since you were already using enlist, you’re testing three separate inputs, not one, and match returns the one title that does match aaa in its entirety.

{{{ [enlist[aaa bbb ccc]match[aaa]] }}} 
is equivalent to
{{{ aaa bbb ccc +[match[aaa]] }}} 

(I think @clsturgeon forgot to delete the :title suffix when he was modifying your filter; match only has two (optional) suffixes, casesensitive (the default) and caseinsensitive.)

I think of contains as belonging to a similar conceptual space as listed: it works exclusively with fields. And in fact, if you have a tiddler titled “aaa”, {{{ [enlist[aaa bbb ccc]contains:title[aaa]] }}} will return aaa! But if there is no tiddler aaa, aaa has no title field, so the filter doesn’t return any results.

This is in contrast to something like [{!!title}], which is really just a synonym for [<currentTiddler>] and doesn’t require an actual tiddler with an actual title field… so there’s probably room for some clarification in the docs.

3 Likes

Thank you @etardiff !

I had not quite reflected on that operators operate on each input item separately, but that makes much sense.

Dang, also an aspect I had not quite reflected over.

This turned out to be quite a lesson. Thank you!

1 Like

I think it best to consider the contains operator as reading “Does a list field contain [value]” with a prefix to choose fieldnames other than the default “list”

The aaa, bbb, ccc tiddlers have to be tiddlers.

Your code wants to read the contains:title of the input elements. Non-existent tiddlers do not have title fields. So it returns nothing.