Thanks TonyM that's very handy !

Would you know if there is a way to return the intersection set as a 
variable for later reuse ?
Then I wouldn't have to decide upfront what to do with the intersection in 
the macro.

I mean something like:
f=intersect("[tag[Todo]] [all[]prefix[a]]", "[tag[Howto]] [all[]prefix[al]]"
)

<<list-links "[enlist< $f$ >sort[]]">>

<$list filter="[enlist<setAinterB>sort[]]">
<$link/>
</$list>

...

But with the proper way to use variables, functions, macros, parameters, 
.... (what these elements are and how to use them in different contextes is 
still unclear to me)

Cheers !


On Thursday, May 7, 2020 at 8:38:23 AM UTC+4, TonyM wrote:
>
> Eric N
>
> Thanks for sharing, I thought I would turn it into a macro because it is a 
> general type of solution.
>
> \define intersect(filter1 filter2)
> <$set name="filterA" filter="$filter1$">
> <$set name="filterB" filter="$filter2$">
> <$set name="setAunionB" filter="[enlist<filterA>] [enlist<filterB>]">
> <$set name="setAnotB" filter="[enlist<filterA>] -[enlist<filterB>]">
> <$set name="setBnotA" filter="[enlist<filterB>] -[enlist<filterA>]">
> <$set name="setAinterB" filter="[enlist<setAunionB>] -[enlist<setAnotB>] 
> -[enlist<setBnotA>]">
> <<list-links "[enlist<setAinterB>sort[]]">>
> </$set></$set></$set></$set></$set>
> \end
>
> <<intersect "[tag[Todo]] [all[]prefix[a]]" "[tag[Howto]] 
> [all[]prefix[al]]">>
>
> But I avoid the list-links macro because its a fixed format
> The following lists only tiddler titles, using the default list widget 
> behaviour, but it easy to present things differentl
> \define intersect(filter1 filter2)
> <$set name="filterA" filter="$filter1$">
> <$set name="filterB" filter="$filter2$">
> <$set name="setAunionB" filter="[enlist<filterA>] [enlist<filterB>]">
> <$set name="setAnotB" filter="[enlist<filterA>] -[enlist<filterB>]">
> <$set name="setBnotA" filter="[enlist<filterB>] -[enlist<filterA>]">
> <$set name="setAinterB" filter="[enlist<setAunionB>] -[enlist<setAnotB>] 
> -[enlist<setBnotA>]">
> <$list filter="[enlist<setAinterB>sort[]]">
>
> </$list>
> </$set></$set></$set></$set></$set>
> \end
>
> For example place this in the blank line above
>   <$link/>, 
>
> or you could add another parameter and use this template
> \define intersect(filter1 filter2 template:"defaulttemplate")
> <$set name="filterA" filter="$filter1$">
> <$set name="filterB" filter="$filter2$">
> <$set name="setAunionB" filter="[enlist<filterA>] [enlist<filterB>]">
> <$set name="setAnotB" filter="[enlist<filterA>] -[enlist<filterB>]">
> <$set name="setBnotA" filter="[enlist<filterB>] -[enlist<filterA>]">
> <$set name="setAinterB" filter="[enlist<setAunionB>] -[enlist<setAnotB>] 
> -[enlist<setBnotA>]">
> <$list filter="[enlist<setAinterB>sort[]]" template="$template$">
>
> </$list>
> </$set></$set></$set></$set></$set>
> \end
>
> Enjoy the possibilities
>
>
> Regards
> Tony
>
> On Wednesday, 6 May 2020 21:14:52 UTC+10, Eric N. wrote:
>>
>> I was stuck in my dev 
>> <https://groups.google.com/forum/#!topic/tiddlywiki/H90XO43PblE> because 
>> I couldn't output the intersection of two filters, each made of several 
>> runs. I didn't find a built-in function to do so, and I couldn't find a 
>> satisfying solution online. But I eventually found my own solution, shared 
>> here.
>>
>> Say I want to get all the tiddlers that satisfy the following conditions 
>> (toy example here, could also have a pair of very complex filters):
>>
>> (has tag Todo OR starts with "a") AND (has tag Howto OR starts with "al")
>>
>> This is computed by the following code, where the output list is enlist
>> <setAinterB>, which is displayed by the list-links macro.
>>
>> <$set name="filterA" filter="[tag[Todo]] [all[]prefix[a]]">
>> <$set name="filterB" filter="[tag[Howto]] [all[]prefix[al]]">
>> <$set name="setAunionB" filter="[enlist<filterA>] [enlist<filterB>]">
>> <$set name="setAnotB" filter="[enlist<filterA>] -[enlist<filterB>]">
>> <$set name="setBnotA" filter="[enlist<filterB>] -[enlist<filterA>]">
>> <$set name="setAinterB" filter="[enlist<setAunionB>] -[enlist<setAnotB>] 
>> -[enlist<setBnotA>]">
>>
>> <<list-links "[enlist<setAinterB>sort[]]">>
>>
>> </$set>
>> </$set>
>> </$set>
>> </$set>
>> </$set>
>>
>>
>> *Caveat* : if a filter output contains double brackets (say a tiddler 
>> named "oh what a [[bad]] name") it breaks the enlist processing, and you 
>> won't have the correct output.
>>
>>
>> Best,
>> Eric
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/cd02e468-aa2d-4108-9f97-d319b5130e2f%40googlegroups.com.

Reply via email to