Yes you are right, my tiddlers have multiples parents.
I think what I am really searching for, is how to use the input tiddlers of a step or a run, as a parameter for other runs.
“:map” was almost it, but not exactly because : “Filter runs used with the :map prefix should return the same number of items that they are passed.”
@pmario TocP allows an alternative field, so if it were important one could have a matrilineal and patrilineal tree, with the children the sum of both. But with Genealogy things can get complex eg steps parents, half siblings etc…
There is absolutely nothing wrong with @saqimtiaz’ solution. For some unknown reason I’m just not partial to manually building title lists from a list of titles. Call me crazy.
How it works:
The parents of the child are put into a variable parentlist to avoid multiple lookups later. Then, all tiddlers with a parent field are filtered (the :filter) by checking if their parent field has some overlap (the :intersection) with the parentlist.
Have a nice day
Yaisog
PS: I really wish there was a :foreach filter run prefix in TW. Probably wouldn’t be too hard to implement, since it’s basically what :filter does without discarding the results…
PPS: I updated the code to use the old-school list operator instead of get[parents]enlist-input[] in the subfilter.
I did have look at that, indeed. However, if the result for each input title would / could be a list of titles, it would again be necessary to join these into a title list and then enlist them like @saqimtiaz did above and I’m no great fan of. I do like map a little better than reduce in this case, as it is slightly more straightforward and/or semantic.
The kin filter is actually an excellent choice here. I used to have it in my wikis. But when you get to a point with a LOT of tiddlers and a tag tree that is multiple levels deep, the kin filter really slows things down compared to using the various tag*-filters, as I don’t think it makes use of the caching mechanism that makes these filters blazingly fast.
For genealogy it’s probably perfect and well documented. Thanks for bringing it up in the context of the OP.
My contribution to this thread is purely for the enjoyment of finding different and hopefully elegant solutions to problems, which is always possible with TW.
Have a nice day
Yaisog
PS: The broader topic interests me, because I’m still looking for an elegant replacement for the kin filter to find all tiddlers in the hierarchy of a tag (tagged with the tag or with the children of this tag and so forth, no matter how many levels deep). The kin filter did that, but very slowly. See also my post a https://groups.google.com/g/tiddlywiki/c/ws05-YAtJ7k/m/uOLPwMABDgAJ.
Thanks for the tip, but actually I’m looking for a filter, not a macro. Even now that macros can be called from a filter, it would require manually assembling a tiddler list from a list of tiddlers, which from my personal perspective is not an elegant solution (unless such filter functionality ever makes it into the core).
Not necessarily. A filter can generate a list of tiddler or be a list of manually entered tiddlers, or both.
Be carful not to create a false dichotomy between filter and macros, The same is commonly also done between filters and nested filters.
All a macro is is capturing your algorithm into something you can invoke in more than one place, and allows you to make it reusable including by providing parameters or variables to that macro.
All a nested filters (lists) are, is wrapping one filter in another and can also provide additional values/variables to the inner filter.
Recursive macros nest one filter in another, in my example below it is the same filter.
A recursive macro is a special case where a macro calls itself, as many times as the data demands, arguably this is the only way to travers a hierarchy of any kind, as you wish to do.
To do a recursive function we need a macro so we can call ourself. Thus a macro is essential.
In this example first-level kicks off the process and each-other-level calls itself as it runs down the hierarchy. When it reaches every leaf (bottom nodes in a hierarchy) , it falls back to the next sibling at the level above.
Here is a really simple example you can edit; try it on tiddlywiki.com
@TW_Tones: Thanks for the example. I believe this is how the TOC macros work.
What I need, however, is not a printed out list-of-lists of the hierarchy, which can be assembled level by level as you show, but all of the tiddlers in the hierarchy in a single list as returned by a single filter call, i.e. something like
that will put all the tiddlers that would appear somewhere in the lists of your example into one single list of tiddlers / variable that I can work with. taggingtree[] is a (yet) fictional operator which would do that.
Have a nice day
Yaisog
@TW_Tones: Thanks for all your work.
But like I said before, the kin filter is too slow for a large wiki, I don’t like manually assembling a title list from a list of titles, and don’t get me started on $wikify which I believe is generally discouraged and should be avoided if possible.
Also, I need to assign the whole title list to a variable or use it as an iterator for a $list widget, not just print it out. That would further complicate things.
I whipped together (or rather copy-pasted) a new recursive filter operator that I will post in a new thread momentarily, so that others may find it should they look for something similar.
Have a nice day
Yaisog
PS: I have posted the new filter operators in a new topic.