Is this a bug? Can't directly use prefixed filter run in function

This does not work:

\function result() :map[{!!title}]

{{{ A B C +[function[result]] }}} --> output nothing

This does work:

\function result() [is[]]:map[{!!title}]

{{{ A B C +[function[result]] }}} --> output A B C

Is this a bug? I would expect the map filter run to operate on the list of tiddler passed to the function, but it doesnt. Operators like is or format can take the list and output it, and only then the :map can be used (tested on the current release and prerelease of tiddlywiki)

See this recent github discussion. Tentative conclusion is that it is a bug.

I don’t understand the code well enough yet to know whether/how to fix it.

Seems like the exact same issue indeed, it’s weird :thinking: For context, here’s the wikitext I was working on that require :map :

\function .get() [<tiddler>get{!!title}]

\function to.json(tiddler,exclude)
-"ℹ️Get the list of relevant fields that are not empty"
[<tiddler>fields:exclude:<exclude>]:filter[.get[]]

-"ℹ️Get the value of each field and reduce to a json object."
:reduce[<accumulator>jsonset{!!title},<.get>]~{}

-"ℹ️Map the result to a tiddler json object."
:map[["$(tiddler)$":$(currentTiddler)$]substitute[]]
\end

\function to.plugin(filter)
-"ℹ️Get the list of tiddlers to be able to use map (bug)"
[is[]]

-"ℹ️Transform the list of tiddlers to json"
:map[to.json{!!title},[created creator modified modifier title]]
+[join[,]]
:map[[{"tiddlers": {$(currentTiddler)$}}]substitute[]]
\end

Tiddler: <$edit field="filter" class="tc-edit-texteditor"/>

<$codeblock code={{{ [subfilter{!!filter}] +[to.plugin[]] }}} />

Not a big deal, for now I’ll just use [is[]] as a pass trough. Thanks for linking the github issue!

@telumire just for clarity the :map “within the function”, operates on the titles “within the function”, not those passed to the function (one at a time). In some filters this may be the same.

  • This may help clarify your understanding.

According to the doc:

The function operator applies a named function to the input titles, and returns the results from the function. The function is invoked once with all of the input titles (in contrast, the filter Operator invokes its function separately for each input title).

The correct behavior would be to apply :map on the list of tiddlers passed to the function. As it stand, :map does not get any input, even one at a time :confused:

This certianly needs clarification. As I understand it, In the calling filter the function is “invoked once with all the input titles, then moves on to the next part of the calling filter”, ie after where the function is named, but what happens next, the function is processed “as a filter” and filters are effectivly a title at a time. “the filter is invoked once, then moves on to the next part of the filter”, In the below example the next part is either 1. Nothing, 2. a per-title filter, 3. all[] tiddlers from next filter step.

\function each.tiddler() [!is[blank]]
1. {{{ [tag[Filters]] }}} <!-- all tiddlers with tag Filters -->

2. {{{ [tag[Filters]each.tiddler[]] }}} <!-- all tiddlers with tag Filters calling each.tiddler -->

3. {{{ [tag[Filters]] [each.tiddler[]] }}} <!-- all tiddlers with tag Filters and all tiddlers (calling) calling each.tiddler -->

FYI: In the above function is “invoked” once for each title given, since a title is never blank, it lists each title given.

  • Try making each.tiddler definition contain nothing.

The thing is I rarelly have trouble using filters, I just know how they work, after more than a decade of using them, but the language, or metaphores we use to describe them could be improved.