Intersection of two filter runs

96 views
Skip to first unread message

Mohammad

unread,
Mar 13, 2019, 12:47:09 PM3/13/19
to TiddlyWiki
I have a code like below

<$vars
 x="1 2 3 4 5"
 y= "2 7 9"
 >
<$list filter="[enlist<x>] +[enlist<y>]" variable=item>
<<item>>
</$list>
 </$vars>

Produces
2 7 9

I expect +run to logically AND the filter output, means those item are in both filter run or the INTERSECTION of two run
e.g. 2

How can I implement this?

--Mohammad

More information

Mark S.

unread,
Mar 13, 2019, 3:14:24 PM3/13/19
to TiddlyWiki

You may not like this version, but it seems to work:

<$vars
 x="1 2 3 4 5"
 y= "2 7 9 3"
f1="[enlist
<x>]-[enlist<y>]"
f2="[enlist
<y>]-[enlist<x>]"
 >
<$list filter="[enlist
<x>] [enlist<y>] -[subfilter<f1>] -[subfilter<f2>]" variable=item>
<
<item>>
</$list>
 </$vars>

I worked the logic out with a venn diagram.

I was pleasantly surprised that the <> brackets were interpolated two levels down.

Thanks!
-- Mark

Mohammad

unread,
Mar 13, 2019, 3:42:23 PM3/13/19
to TiddlyWiki
Many thanks Mark,
 Yes, it works! I am wondering how can I develop a macro to find the intersection of any two filter runs!
Seems difficult.

--Mohammad

Mohammad

unread,
Mar 14, 2019, 12:22:40 AM3/14/19
to TiddlyWiki
Hi again,
 I tried to do something like this

\define intersect-item(filter, item)
<$list filter="[<__item__>] -[subfilter<__filter__>]" variable="result" emptyMessage=<<__item__>> >
</$list>
\end

\define intersect(flt1, flt2)
<$list filter=<<__flt2__>> variable=item >
<$macrocall $name="intersect-item" filter=<<__flt1__>> item=<<item>> />
</$list>
\end


<$vars
 x="7 8 -1 -3 9 11"
 y= "1 2 3 4 5 6 7 8 9"
 >
<$macrocall $name=intersect 
   flt1="[enlist<x>]"
   flt2="[enlist<y>]"
/>
</$vars>

The procedure is, I check every item in filter2 output to see if it is in filter1 output.
If so, I display it, if not, I ignore it!

I am not sure if the code is optimize and according to TW rules and standard.

Application: I have two set of tiddlers, for example those have property1 and those have property2. I want to show 
tiddlers have both properties!



Give me your comments.

--Mohammad


On Wednesday, March 13, 2019 at 10:44:24 PM UTC+3:30, Mark S. wrote:

Mohammad

unread,
Mar 14, 2019, 12:28:38 AM3/14/19
to TiddlyWiki
One point:
The Tiddlywiki +run does not necessarily simulate the logical AND operator!

--Mohammad

Mohammad

unread,
Mar 14, 2019, 12:33:25 AM3/14/19
to TiddlyWiki
Further input

<$vars
 x="7 8 -1 -3 9 11"
 y= "1 2 3 4 5 6 7 8 9"
 >
<$list filter="[enlist<x>] [enlist<y>] +[sortan[]]">
<<currentTiddler>>
</$list>

The OR logical operator correctly works!


So, is there a bug in +run filter expression!

--Mohammad



On Wednesday, March 13, 2019 at 8:17:09 PM UTC+3:30, Mohammad wrote:

Mark S.

unread,
Mar 14, 2019, 12:39:52 AM3/14/19
to TiddlyWiki
I don't think it qualifies as a true logical operator the way run and -run do. I think of it more of as a funnel > operator, telling the next run to use the previous run as input. I'm not sure that is the same as a true intersection. That's why I did all the extra steps to form the intersection. If the + was a true AND, I wouldn't have had to do that.

-- Mark

Mohammad

unread,
Mar 14, 2019, 1:00:07 AM3/14/19
to TiddlyWiki
Thanks Mark!

Just one more question: What is your opinion on the intersection code above?

In real world! In Tiddler Commander I have a filter search to filter some tiddlers based a certain criteria and then I have a checkbox widget to select among those tiddlers!
If I change the filter search (using textbox), I have still the selected tiddlers using checkbox there! So, I need extra step to determine if the
selected tiddlers by checkbox widget are existed in the new filter search. That the reason I have to find intersection.

Thank you again Mark!

--Mohammad

Mark S.

unread,
Mar 14, 2019, 10:56:37 AM3/14/19
to TiddlyWiki
Here's a trimmer version of the previous macro. It seems to work and doesn't require calling a macro on each list item:

\define f1() [enlist<x>]-[enlist<y>]
\define f2() [enlist<y>]-[enlist<x>]

<$vars
 x
="1 2 3 4 5"

 y
= "2 7 9 3"

 
>
<$list filter="[enlist<x>] [enlist<y>] -[subfilter<f1>] -[subfilter<f2>]" variable=item>
<<item>>
</$list>
 </
$vars>

I think to find out which version is more efficient you'd have to load up a huge array and time the difference. With only a handful of items, the priority is which code is easiest to read and fix later on ?

-- Mark

Mohammad

unread,
Mar 14, 2019, 11:06:24 AM3/14/19
to TiddlyWiki
Thanks Mark!

Added to TW-Script.

Cheers
Mohammad
Reply all
Reply to author
Forward
0 new messages