TW5 : Get unique values from nested lists output

140 views
Skip to first unread message

Mohamed Amin

unread,
Feb 7, 2020, 11:30:50 PM2/7/20
to TiddlyWiki
Hello All,

It may be trivial , but I tried to search the group with no luck, so appreciate you help here.

Suppose that I have a nested "lists" like the following (FOR EACH "shadow tiddler" GET "root value") :-

<$list filter="[all[shadows]sort[title]]" >
   <$list filter="[<currentTiddler>split[/]nth[2]]" >

   </$list>
</$list>

Note that the Number of rows in the output will equal to the number of shadow tiddlers (> 1000)

Now, what should I do to get only the unique values (around 15 value)

Thanks in advance

Mark S.

unread,
Feb 8, 2020, 9:49:45 AM2/8/20
to TiddlyWiki
A general technique when you need to take the output of a system of nested
lists and make them into one list is to put the nested lists in a macro. Then
wikify the output of the macro, turn it back into a list with "enlist", and then
perform any final sorting steps. Thus:

\define roots()

<$list filter="[all[shadows]sort[title]]" >
   <$list filter="[<currentTiddler>split[/]nth[2]]" >

   </$list>
</$list>
\end

<$wikify text=<<roots>> name="roots2">
<$list filter="[enlist<roots2>sort[]]">

</$list>
</$wikify>

Mohamed Amin

unread,
Feb 8, 2020, 4:02:01 PM2/8/20
to TiddlyWiki
Thank you VERY much Mark S. for your reply, really appreciate it 

Mat

unread,
Feb 9, 2020, 4:42:42 AM2/9/20
to TiddlyWiki
This thread pushed me to finally request "memory operators" after having it linger in my head for probably a few years. Please comment there or like/dislike,, especially if you have technical insights about why it makes sense or not.

<:-)

TonyM

unread,
Feb 9, 2020, 6:39:41 AM2/9/20
to TiddlyWiki
Mat

Interesting suggestion. When I recently raised the push pop suggestion it was pointed out this kind of function works already. Which makes me think there is a possibility of an existing pattern that can do this.

I will explore and report

Tony

TonyM

unread,
Feb 9, 2020, 7:06:41 AM2/9/20
to TiddlyWiki
This is not the pattern I was thinking of but it does what the original request wanted?

I call these values the namespace

<$list filter="[all[shadows]removeprefix[$:/]splitbefore[/]removesuffix[/]]">

</$list>

Or you could add prefix at the end $:/

Mohamed Amin

unread,
Feb 12, 2020, 6:10:10 PM2/12/20
to TiddlyWiki
Thanks a lot TonyM for the code, it's very nice to know that I can do it only in 1 step (normally I do it in multi steps so I can see my way while searching) 

TonyM

unread,
Feb 12, 2020, 7:10:14 PM2/12/20
to TiddlyWiki
Push pop

Each time a macro calls a macro, as in toc or recursive macros that call themself, a variable which is set is valid for that call of the macro. When it ends it reverts to the previous value.

In a way each set of the same variable is a push, and when you arrive at the /$set its a pop.

From this idea I want to try and create what was implied in the original post and my response

Regards
Tony

Mat

unread,
Feb 13, 2020, 12:36:04 AM2/13/20
to TiddlyWiki
TonyM wrote:

When I recently raised the push pop suggestion it was pointed out this kind of function works already.


Not sure what "works already" would refer to. Storing and recalling variables obviously works (just use e.g $set) - but my request is about doing this directly inside/during the filter run. 

<:-)

TonyM

unread,
Feb 13, 2020, 5:43:19 AM2/13/20
to TiddlyWiki
Mat,

I did some more on this today. Basically having a macro which one passes a set of filters and they are automatically nested, to do this I need to push and pop each filter, using first and butfirst operators. However each filter must stand on its own and where necessary reference the nesting lists variable eg currentTiddler.

By building this I am creating a "meta filter", and using set in a recursive manner to push and pop.

As you can see from my example before I managed to place this example directly inside/during the filter run. But it is hard to generalise this to make it possible in every case. It would be nice to identify the gap and find an elegant way to do it. However perhaps a macro replacement for a list widget that can accept multiple filters and automatically nest them is an answer?

The use of +filters -filters and subfilters are also an option that can address this kind of issue, yet I am yet to uncover any universal patterns to use, to be able to use a single filter for nested problems.

Regards
Tony

Regards
Tony

TonyM

unread,
Feb 13, 2020, 5:45:00 AM2/13/20
to TiddlyWiki
Mat,

I also support something of the ilk of your suggestion 

Request: Memory variable filter ops #4452


Regards
Tony

On Thursday, February 13, 2020 at 4:36:04 PM UTC+11, Mat wrote:

Mat

unread,
Feb 13, 2020, 12:45:43 PM2/13/20
to TiddlyWiki
TonyM wrote:
As you can see from my example before [...] 

Which example?
 
I don't quite understand your description here but you do mention "nesting" a lot. However, a main idea with my proposal is to avoid manually nesting stuff by enabling a "flat" filter so you can directly use it in e.g a single listwidget. We'd achieve the same output by nesting listwidgets - in fact that is exactly what we currently do - so when you talk about adding macros to it, I suspect that this would only be another optional but also complex solution - no?

<:-)

TonyM

unread,
Feb 13, 2020, 5:15:26 PM2/13/20
to TiddlyWiki
Mat,

This example, where by another method, I avoided the problem
You say
I don't quite understand your description here but you do mention "nesting" a lot. However, a main idea with my proposal is to avoid manually nesting stuff by enabling a "flat" filter so you can directly use it in e.g a single listwidget. We'd achieve the same output by nesting listwidgets - in fact that is exactly what we currently do - so when you talk about adding macros to it, I suspect that this would only be another optional but also complex solution - n 

I understand your desire to reduce the need for nesting when it comes to the list widget and filters,  the thing is sometimes; 
  • nesting can be avoided altogether to get the same result as in my example and
  • in other cases we move the nesting inside the filter (perhaps like your proposal)
  • In my example I am talking about a macro that automatically handles the nesting of multiple filters (in this case you provide a flat set of filters)
Of course with support perhaps such a macro could become a new widget or the list widget extended.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages