list tiddlers title with a delimiter (a character between items) resulting from a complex filter

97 views
Skip to first unread message

Atronoush Parsi

unread,
Aug 1, 2021, 12:48:12 PM8/1/21
to tiddl...@googlegroups.com
I am sure this has been addressed before but I cannot find it in forum

Assume you have a complexe filter that results in an output containing few tiddlers. Then you want to show them with a delimiter e.g. pipe (|)
One solution is below. I am looking for a more efficient solution! I assume here TW makes the search two times! I know we can use a $set widget here, but what better solution do you propose?

<$list filter="[all[current]!is[system]has[one]] [all[current]!is[system]has[two]] [all[current]search:text[three] -[last[]]">
<$link/> | 
</$list>
<$list filter="[all[current]!is[system]has[one]] [all[current]!is[system]has[two]] [all[current]search:text[three]  +[last[]]">
<$link/>
</$list>

PMario

unread,
Aug 1, 2021, 1:51:20 PM8/1/21
to TiddlyWiki
Hi,

I don't understand the purpose. all[current] will only return 1 title. The currentTiddler. So why do you use [last[]] here?

-mario

Atronoush Parsi

unread,
Aug 1, 2021, 2:39:39 PM8/1/21
to tiddl...@googlegroups.com
Mario,
 These filters are placed inside some other $list, I also changed it for this question. I write the question here in a simpler way

<$list filter="[tag[foo]] [tag[bar]] [tag[tw]]"><$link/> | </$list>

The purpose is to generate

Tid One | Tid Two | Tid Three

the above code adds | to the end of the list and I do not want that!

--Atro

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/af4a5ac3-13e3-4f62-9a91-7fc765e20c80n%40googlegroups.com.

unread,
Aug 1, 2021, 5:23:13 PM8/1/21
to TiddlyWiki
Hi Atro,

Thanks for posting this. The same issue has been bugging me for a while but I had never looked into the operators to solve it until now. Simply use the join operator:

<$list filter="[[foo]] [[bar]] [[tw]] +[join[ | ]]"> <$link/></$list> should give you what you're looking for, ie. foo | bar | tw.

Best,

unread,
Aug 1, 2021, 5:33:23 PM8/1/21
to TiddlyWiki
Oops, I shouldn't comment just before heading to bed. My proposed solution gives the right string but without the active links. The join operator does seem like a good place to start though…

Best,

TW Tones

unread,
Aug 1, 2021, 8:45:16 PM8/1/21
to TiddlyWiki
Before you go too far 
I added missing ] before the last operator
How do you insert the code view now in Google groups/email.

Eric Shulman

unread,
Aug 1, 2021, 9:32:41 PM8/1/21
to TiddlyWiki
On Sunday, August 1, 2021 at 9:48:12 AM UTC-7 Atronoush wrote:
I am sure this has been addressed before but I cannot find it in forum
Assume you have a complex filter that results in an output containing few tiddlers. Then you want to show them with a delimiter e.g. pipe (|)
One solution is below. I am looking for a more efficient solution! I assume here TW makes the search two times! I know we can use a $set widget here, but what better solution do you propose?

Overall, an interesting challenge in TiddlyWiki filtering.
I had fun trying several approaches...

The most efficient one is to use $set, as you suggested, like this:
<$set name="out" filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$list filter="[enlist<out>butlast[]]"><$link/> | </$list>
<$list filter="[enlist<out>last[]]   "><$link/>   </$list>
</$set>
The improvement is that the filter is only evaluated once, with two enlist[] operators added.  Depending upon how many matching tiddlers are found, and assuming a reasonably short list, the enlist[] operators are likely to be more efficient than evaluating the filter twice.  Also, note the use of -[last[]] in your initial post is incorrect... it doesn't actually remove the final item. The correct operator to use is butlast[], as shown above.

I also tried this:
<$set name=out filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$vars last={{{ [enlist<out>last[]] }}}>
<$list filter="[enlist<out>]"><$link/> <$text text={{{ [<currentTiddler>!match<last>then[|]] }}}/> </$list>
</$vars>
</$set>
The improvement here is the same as above, except that uses an extra variable ("last") and an inline filter to decide when to insert the "|" between items, so it's obviously a bit less efficient.

Lastly, I tried this:
<$vars lb="[[" rb="]]">
<$set name=out filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$wikify name="out" text="""<$list filter="[enlist<out>addprefix<lb>addsuffix<rb>join[ | ]trim[ | ]]" ><$link/></$list>""">
   <<out>>
</$wikify>
</$set>
</$vars>
Of course, this is even less efficient than the previous solutions, as it uses wikify to produce the output, and needs to explicitly add brackets around the links.  However, it does demonstrate the use of join[] and trim[] to insert the "|" between items.

-e

Atronoush Parsi

unread,
Aug 2, 2021, 2:43:19 PM8/2/21
to tiddl...@googlegroups.com
Thank you all! Many useful things to learn!

@Eric,
I go with the $set widget solution, for me it is simpler and as you explained seems to have the better performance!

Cheers
Atro

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Mohammad Rahmani

unread,
Aug 3, 2021, 9:29:11 AM8/3/21
to tiddl...@googlegroups.com
Very nice solution Eric!

One question:



Best wishes
Mohammad


On Mon, Aug 2, 2021 at 6:02 AM Eric Shulman <elsd...@gmail.com> wrote:
On Sunday, August 1, 2021 at 9:48:12 AM UTC-7 Atronoush wrote:
I am sure this has been addressed before but I cannot find it in forum
Assume you have a complex filter that results in an output containing few tiddlers. Then you want to show them with a delimiter e.g. pipe (|)
One solution is below. I am looking for a more efficient solution! I assume here TW makes the search two times! I know we can use a $set widget here, but what better solution do you propose?

Overall, an interesting challenge in TiddlyWiki filtering.
I had fun trying several approaches...

The most efficient one is to use $set, as you suggested, like this:
<$set name="out" filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$list filter="[enlist<out>butlast[]]"><$link/> | </$list>
<$list filter="[enlist<out>last[]]   "><$link/>   </$list>
</$set>

Is it possible to use subfilter instead of enlist here? Which is recommended?

<$set name="out" filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$list filter="[subfilter<out>butlast[]]"><$link/> | </$list>
<$list filter="[subfilter<out>last[]]   "><$link/>   </$list>
</$set>


 
The improvement is that the filter is only evaluated once, with two enlist[] operators added.  Depending upon how many matching tiddlers are found, and assuming a reasonably short list, the enlist[] operators are likely to be more efficient than evaluating the filter twice.  Also, note the use of -[last[]] in your initial post is incorrect... it doesn't actually remove the final item. The correct operator to use is butlast[], as shown above.

I also tried this:
<$set name=out filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$vars last={{{ [enlist<out>last[]] }}}>
<$list filter="[enlist<out>]"><$link/> <$text text={{{ [<currentTiddler>!match<last>then[|]] }}}/> </$list>
</$vars>
</$set>
The improvement here is the same as above, except that uses an extra variable ("last") and an inline filter to decide when to insert the "|" between items, so it's obviously a bit less efficient.

Lastly, I tried this:
<$vars lb="[[" rb="]]">
<$set name=out filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$wikify name="out" text="""<$list filter="[enlist<out>addprefix<lb>addsuffix<rb>join[ | ]trim[ | ]]" ><$link/></$list>""">
   <<out>>
</$wikify>
</$set>
</$vars>
Of course, this is even less efficient than the previous solutions, as it uses wikify to produce the output, and needs to explicitly add brackets around the links.  However, it does demonstrate the use of join[] and trim[] to insert the "|" between items.

-e

--

Eric Shulman

unread,
Aug 3, 2021, 10:15:31 AM8/3/21
to TiddlyWiki
On Tuesday, August 3, 2021 at 6:29:11 AM UTC-7 Mohammad wrote:
<$set name="out" filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$list filter="[enlist<out>butlast[]]"><$link/> | </$list>
<$list filter="[enlist<out>last[]]   "><$link/>   </$list>
</$set>

Is it possible to use subfilter instead of enlist here? Which is recommended?

<$set name="out" filter="[tag[HelloThere]] [tag[About]] [tag[Platforms]]">
<$list filter="[subfilter<out>butlast[]]"><$link/> | </$list>
<$list filter="[subfilter<out>last[]]   "><$link/>   </$list>
</$set>

This is almost certainly less efficient than using enlist<out>, as it would still be evaluating the original filter expression (to $set the value of "out"), but then subfilter<out> does another two lookups into the tiddler store, even if all the terms of the filter are literal tiddler names, while enlist<out> is simply copying the already captured literal tiddler names directly into the current expression.

-e

Mohammad Rahmani

unread,
Aug 3, 2021, 11:03:33 AM8/3/21
to tiddl...@googlegroups.com
Eric,
Thank you very much for clarification!


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages