What construct is passed along inside the filter expression?

65 views
Skip to first unread message

Mat

unread,
Mar 21, 2020, 6:53:36 AM3/21/20
to TiddlyWikiDev
Within a filter expression, what kind of construct is passed from one filter step to the next? I'm guessing it is a list but maybe it is an array or some tree?

Does this construct have a predefined variable name? (e.g "filter-output-thus-far")

Does this construct differ in nature if it is passed from one filter step to the next vs from a filter run to the next filter run, within the filter expression? I.e is it still the same list/array/tree or does it change "form" when it leaves a run and becomes input to the next run.

...or do I perhaps have the totally wrong picture of how this works? 

Thanks.

<:-)

PMario

unread,
Mar 21, 2020, 7:34:34 AM3/21/20
to TiddlyWikiDev
Hi,

Filter runs are basically "independent" and "start over" with all tiddlers.

Filters produce an array of "titles", which is passed from 1 run to the next run, if it has a leading + symbol. Then the following run uses the output of the previous run.

That's basically it. So filter runs don't have an "internal" memory.

Filters themself can _not_ store internal info into variables. ... You'll need to use <$set name=abc filter="xx"> if you want to write a filter output to a variable and then in the "next / nested" filter use it with [<varName>]

-mario

Mat

unread,
Mar 21, 2020, 8:07:45 AM3/21/20
to TiddlyWikiDev
Thanks for your reply, Mario!

So the array of titles which is passed from one run to the next, is this addressable as a unit (i.e in the js code)? 

<:-)

TonyM

unread,
Mar 21, 2020, 8:19:34 AM3/21/20
to TiddlyWikiDev
Mat

I would add that not withstanding the limitations you ask about there are few limits to filters the trick is learning how to ask the question. I think can think of two facts about filters

With all the operators available each run within a filter can transform the result of the previous run in many ways. The key question is what result will you have at the end.

Each filter can make use of the output of macros, variables and fields including other filters. If you need an intermediate result don't hesitate to nest filters. Using set which has a filter option or the use triple curly braces to provide the result of any filter to any parameter.

You may think my response seems off topic but to me its about learning to work with the tools a different way to achieve the same result. Any of us enthusiasts would love the chance to achieve the apparently impossible if you can produce an example which suggests its incomplete. If you do you would get a gold star and a solution would be developed.

By the way Evans formula plugin may not have this limitation.

Regards
Tony

TonyM

unread,
Mar 21, 2020, 8:23:19 AM3/21/20
to TiddlyWikiDev
Post script

I think of a filter as a seive that only lets particular things through. In that case the only arrays are the input and the output.

Tony

Jeremy Ruston

unread,
Mar 21, 2020, 6:01:32 PM3/21/20
to TiddlyWikiDev
Hi Mat

The filter evaluation system maintains two lists/arrays: one is the current run, and one is the accumulated results so far. The arrays aren’t stored in variables or named, so it isn’t possible to select/refer to any other arrays. 

Your intuition is correct that filters would be a lot more powerful if they could work with more complex structures, particularly dictionaries of key:value pairs.

Best wishes

Jeremy


--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/a39b7494-f723-4c0b-8f41-4ccff9423130%40googlegroups.com.

Mat

unread,
Mar 21, 2020, 7:20:57 PM3/21/20
to TiddlyWikiDev
TonyM wrote:

[...] If you need an intermediate result don't hesitate to nest filters.


If you by "nest filters" mean "nest listwidgets" then, yes, I do hesitate to do this - this is actually the very background for my question here, as expressed in the Memory variable filter ops request. Now, (somewhat embarassed) I've realized that request doesn't make any sense in its current form. So in order to formulate the request properly I needed to understand the question posted here.
 

[...] if you can produce an example which suggests its incomplete. If you do you would get a gold star and a solution would be developed.


(As given in the gh thread), I think this simple example shows an incompleteness: 

"[tag[foo]get[text]]" - now which tiddler does the output text belong to? But my point (in the not-quite-sensical gh request) is not to find the tiddler - that can be done by nesting listwidgets. My point is that it should be possible to do this with one filter expression. 

<:-)


Mat

unread,
Mar 21, 2020, 7:44:53 PM3/21/20
to TiddlyWikiDev
Jeremy Ruston wrote:
[...] The arrays aren’t stored in variables or named, so it isn’t possible to select/refer to any other arrays.  
[...] filters would be a lot more powerful if they could work with more complex structures, particularly dictionaries of key:value pairs.


Backseat driver stepping up on the banana box, raising his finger:

The output from a filter run is some kind of list of elements. If this is wrapped in brackets, it is a single element (this is why we must sometimes use enlist[] to split up this "element"). Now, in the ListWidget, the output from a filter can be set to be a variable as is done via the ListWidget variable attribute. So, whouldn't it be possible to do this within the filter expression for each filter run, i.e by wrapping the filter run output items in brackets and giving it a name? And this could be referred to in a multi-run expression?

If this makes absolutely no sense, anybody just say so and I'll drop it and instead just post a "TWX request" without "clever solutions" :-)

<:-)

TonyM

unread,
Mar 21, 2020, 8:58:37 PM3/21/20
to TiddlyWikiDev
Mat,

Believe it or not, I do know where you are coming from and I support a well designed feature to achieve what you want. But I do urge caution. At present a filter tends to generate a one many or no specific list of items. The point I believe I am making is however there are already quite elegant methods to achieve what you ask.
  • In the case of your example using the get, is asking for the content of that field on every tiddler to become the list, you are getting what you ask for,
  • and this feature is often needed.
  • But no, in fact you are asking for the tiddler name and the content of a field.
The way I would answer this would be a number of ways, but with two possible examples below
<$list filter="[tag[Languages]]">

   Title=<
<currentTiddler>><br>{{!!text}}<br>
</$list>

<hr>

<$list filter="[tag[Languages]]">

   Title=<
<currentTiddler>><br><$text text={{{ [all[current]get[text]] }}}/><br>
</$list>

But because I feel for what you are asking, I have being working on a macro that would look like this

<<nested-filters "[tag[Languages]]" "[<f1>get[text]]" """Title: <<f1>> vlue: <<f2>>""">>
:Or
<<nested-filters "[tag[Languages]]" "[
<f1>get[text]]" """
Title: <
<f1>> vlue: <<f2>>
""">>
:Or with a macrocall

Where the last item is what to display, or could be a listtemplate
This would generate behind the scenes as many nested lists as filters provided.

  • But other tricks are available depending on the content of the field you would like to extract.

For One way to improve filters and perhaps resolve this gap would be to consider
<$list filter="[!is[system]has[caption]] +[addprefix{!!caption}addprefix[:]]">

</$list>
The above (if it worked) would output a compound value delimited by ":"


Lets say we could use the & or pipe | instead of the +
Where the second run operates on each title as the currenttiddler
filter="[!is[system]has[caption]] &[get[title]addprefix{!!caption}addprefix[:]]"
Resulting in
caption1:tiddlername1
caption2:tiddlername2
Or
\define break() :<br>
filter
="[tag[Languages]] &[addsuffix[<break>]get[text]]"

Resulting in
tiddlername1
:
tiddler text1
tiddlername2
tidler text2


Again, where the second run is applied to each title as if it were the currentTiddler.
....
ie {!!caption} refers to the caption of each of the resulting tiddlers.

Splitting such delimited titles is trivial.

Food for thought?

Regards
Tony


TonyM

unread,
Mar 21, 2020, 9:02:21 PM3/21/20
to TiddlyWikiDev
Post script,

I would love to see a short form for all[current]

eg here or here[] which could also allow a switch to apply to the currentTittle in the list.

Tony 
Reply all
Reply to author
Forward
0 new messages