How to recursively traverse all child tiddlers using the function pragma?

Hi everyone,

Suppose we have a task called [[Meeting with friends]]. This task can be split into several subtasks (children), and each subtask can in turn be split into further subtasks.

When a subtask is created, its parent field is set to the title of its parent task. Given this structure, how can I recursively traverse all subtasks of a task using TiddlyWiki’s function pragma?

I’ve already found a way to recursively traverse all child tiddlers using a procedure, and it works correctly. However, it doesn’t feel very elegant to me. Ideally, I’d like to achieve the same result using a function pragma instead.

Does anyone have suggestions or examples for doing this with function?

Here is the procedure-based approach I’m currently using to traverse all child tiddlers:

\procedure travel-recurse(root)
\function get-formatted-title() [<currentTiddler>format:titlelist[]]
<$list filter="[parent<root>]">
	<<get-formatted-title>>
	<$transclude $variable="travel-recurse" root=<<currentTiddler>>/>
</$list>
\end

<$wikify name="tasks-list" text="""<$transclude $variable="travel-recurse" root="Meeting with friends"/>""">
	<ul>
		<$list filter="[enlist<tasks-list>]">
			<li>
				<$link to=<<currentTiddler>>>
					<<get-task-caption>>
				</$link>
			</li>
		</$list>
	</ul>
</$wikify>

I’ve also created a complete demo site for this question, which you can test directly at :point_right: https://com.tiddlyhost.com/.

You could have a look how my tocP plugin macros are created

Hi, thank you for the suggestion. However, it doesn’t quite fit my use case.
The example is implemented entirely with the define macro, while I’m trying to solve this problem using a function pragma.

More specifically, I’m looking for a way to recursively traverse all child tiddlers using only filter expressions.

\function recurse.with.self(t) [<t>] [.recurse<t>]

\function .recurse(t) [all[tiddlers]parent<t>] :map:flat[recurse.with.self<currentTiddler>]

{{{ [recurse.with.self[Meeting with friends]] }}}

The above is untested but should point you in the right direction.

3 Likes

Thanks for your reply — that’s exactly the answer I was looking for. This is awesome!