Subfilter operator is only sometimes a selection constructor

In the documentation, the subfilter operator is tagged as a selection constructor, but after investigating the code and trying some examples, I find that it doesn’t always ignore its input.

This simple example from the documentation illustrates it as a selection constructor:

[subfilter[one two three]addsuffix[!]]

If this example is modified to add input, then the input is ignored. IOW, the following has the same output as the above:

[tag[Filter Operators]subfilter[one two three]addsuffix[!]]

But the subfilter operator is not inherently a constructor, it only inherits its “constructor-ness” from the filter specified in its operand. Since the filter one two three is a constructor, the subfilter acts as a constructor.

If the operand instead is a selection modifier, then the subfilter operator will act as a selection modifier. For example, the following will select the 5 most recently modified tiddlers tagged with “Filter Operators”:

<$vars recent_mods="[has[modified]!sort[modified]limit[5]]">

{{{[tag[Filter Operators]subfilter<recent_mods>addsuffix[!]]}}}
</$vars>

So I think the selection constructor tag is there only because it can be a constructor, not because it must be a constructor.

This behavior makes sense. If subfilter were only a selection constructor, then it would only be useful on the leftmost side of a filter step.

1 Like

I don’t have the details handy but you can use subfilter in the form

filter +[subfilter<myfilter>]

I never took any notice of the selector / constructor definition and considered subfilter to be a way to bring a filter in from elsewhere (any filter of any type), eg a macro. So I never questioned if it were a selector / constructor. I note the only indication it is a “selection constructor” is it is tagged “Selection Constructors”. The example in the ## subfilter Operator documentation is; [all[tiddlers]subfilter<myFilter>]
Then ALL it’s example tiddlers are all of the form [subfilter...

Does this make sense?

Having taken a fresh look at this, yes you are absolutely correct and that is an oversight on my part trying to answer someone’s query in a rush.

Could you perhaps add some clarification to the documentation for subfilter[]?

Yes, I’ll take a stab at it. One of the reasons I wrote this post is to help me understand the operator better so I can successfully improve the documentation.

I created this pull request for updates to the subfilter docs: Add subfilter operator examples and mention when it is a constructor by btheado · Pull Request #6155 · Jermolene/TiddlyWiki5 · GitHub