Flatten a nested list?

101 views
Skip to first unread message

Mat

unread,
May 17, 2020, 2:17:22 PM5/17/20
to TiddlyWiki
I want a flat list of all the tiddlers in the inner list so I can pick out a title with e.g nth[3]. How?
The following doesn't work but illustrates the problem:

\define all()
<$list filter="[tag[foo]]">
<$list filter="[tag{!!title}]">

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

<$set name=a value=<<all>>>
{{{ [enlist<a>nth[3]] }}}
</$set>

Thank you!

<:-)

Mark S.

unread,
May 17, 2020, 5:32:40 PM5/17/20
to TiddlyWiki
Possibly by using some form of Wikify instead of Set.

Mat

unread,
May 17, 2020, 5:38:33 PM5/17/20
to TiddlyWiki
Mark S. wrote:
Possibly by using some form of Wikify instead of Set.

Thanks. I tried that but it removes the brackets from titles with spaces so they're not identifiable anymore... I can imagine it would be possible with something that adds brackets as prefixes and suffixes but it's just so messy. I'm hoping someone has better ideas.

Maybe my OP is overgeneralizing though. This describes my actual problem if it changes anything:

The tiddlers in the inner listwidget have a number field, e.g "number:7"

I want to calculate the average of the all the numbers, i.e add up all the number fields and also count how many tiddlers there are that are tagged with any of the parent tags.

<:-)

TonyM

unread,
May 17, 2020, 6:59:16 PM5/17/20
to TiddlyWiki
Mat,

In this case I may be tempted to use the kin filter as it is in part designed for this situation.

I have played with wikify and the set widgets select parameter with no answer so far, but I have a clear memory of a solution to this. I will continue to investigate.

However I will add here none of the intuative methods work and this is a gap in the way tiddlywiki works, this should be a trivial issue. 

I expect Eric or Jeremy could answer this in a moment but the fact we three, Mat, Mark S and TonyM struggle with it for get newby's

SOmething needs improvment here.

Regards
Tony

Eric Shulman

unread,
May 17, 2020, 8:02:07 PM5/17/20
to TiddlyWiki
On Sunday, May 17, 2020 at 3:59:16 PM UTC-7, TonyM wrote:
I expect Eric or Jeremy could answer this in a moment but the fact we three, Mat, Mark S and TonyM struggle with it for get newby's
 
On Monday, 18 May 2020 07:38:33 UTC+10, Mat wrote:
Mark S. wrote:
Possibly by using some form of Wikify instead of Set.

This addresses the goal of the generalized OP:
\define all()
<$list filter="[tag[foo]]">
<$list filter="[tag{!!title}]">

   
<$text text="[["/><$text text=<<currentTiddler>>/><$text text="]]"/><br>
</$list>
</
$list>
\end

<$wikify name="a" text=<<all>>>
{{{ [enlist<a>nth[3]] }}}
</$wikify>

* <<all>> explicitly outputs all tiddler titles with enclosing doubled square brackets, even if an individual title doesn't *need* it (i.e., no spaces)
* The macro is then wikified to capture the output

Maybe my OP is overgeneralizing though. This describes my actual problem if it changes anything:
The tiddlers in the inner listwidget have a number field, e.g "number:7"
I want to calculate the average of the all the numbers, i.e add up all the number fields and also count how many tiddlers there are that are tagged with any of the parent tags.

and, here's a solution to the more specific use-case (gather "number" field values and calculate average)
\define all()
<$list filter="[tag[Foo]]">
<$list filter="[tag{!!title}]">
   
{{!!number}}
</$list>
</
$list>
\end

<$wikify name="a" text=<<all>>>
<$vars total={{{ [enlist<a>sum[]] }}} count={{{ [enlist<a>count[]] }}}>
total
=<$text text=<<total>> />
count=<$text text=<<count>> /
>
average
=<$text text={{{ [<total>divide<count>] }}} />
</$vars>
</
$wikify>

let me know how it goes...

enjoy,
-e
 

Mat

unread,
May 18, 2020, 1:55:05 PM5/18/20
to TiddlyWiki
Eric Shulman wrote:
and, here's a solution to the more specific use-case (gather "number" field values and calculate average)
\define all()
<$list filter="[tag[Foo]]">
<$list filter="[tag{!!title}]">
   
{{!!number}}
</$list>
</
$list>
\end

<$wikify name="a" text=<<all>>>
<$vars total={{{ [enlist<a>sum[]] }}} count={{{ [enlist<a>count[]] }}}>
total
=<$text text=<<total>> />
count=<$text text=<<count>> /
>
average
=<$text text={{{ [<total>divide<count>] }}} />
</$vars>
</
$wikify>


Much appreciated Eric! It seems the vars enlist ops need the raw suffix, i.e enlist:raw to not remove duplicates. Here's a demo: http://flattenlist.tiddlyspot.com/
Thank you!

<:-)
Reply all
Reply to author
Forward
0 new messages