Is there a way to pass <$count> (or similar) to Evan's <<formula>> for calculation?

74 views
Skip to first unread message

hubertgk

unread,
Mar 30, 2018, 2:04:09 PM3/30/18
to TiddlyWiki
Well, I know it's not really possible because <$count> is not a function. But I was hoping that someone found a way, perhaps using javascript, to count tiddlers based on a filter and then pass that number as a parameter to a macro.

I'd be very grateful for suggestions and, again, thank you for your time and help!

Best regards,
Hubert

Mat

unread,
Mar 30, 2018, 2:30:25 PM3/30/18
to TiddlyWiki
Well, there is the count filter so you can get the amount of tids as output from a filter. This can be passed on to a macro, I'm pretty sure.

<:-)

Matthew Lauber

unread,
Mar 30, 2018, 2:34:09 PM3/30/18
to TiddlyWiki
Use the filter field of the <$set> wiget to to set a variable equal to the count insidethere use the <$macrocall> widget to pass the variable to the <<formula>> macro.

hubertgk

unread,
Mar 30, 2018, 2:36:57 PM3/30/18
to TiddlyWiki
Thanks Matthew, could you please provide some example code?

Jed Carty

unread,
Mar 30, 2018, 2:38:45 PM3/30/18
to TiddlyWiki
Wow, I missed a lot of new things. I wasn't aware of the count operator. To give some examples of what Mat is talking about here is how you would use it to get an input to a macro (copy and paste this into a tiddler on tiddlywiki.com to see what the two methods do):

\define DoSomething()
The filter counted $(number)$ tiddlers
\end

\define DoSomethingElse(number)
The filter counted $number$ tiddlers
\end

!!Method 1 - Substitution

<$list filter='[tag[HelloThere]count[]]' variable='number'>
<<DoSomething>>
</$list>

!!Method 2 - Macrocall widget

<$list filter='[tag[HelloThere]count[]]' variable='number'>
<$macrocall $name=DoSomethingElse number=<<number>>/>
</$list>


As Matthew Lauber said, you can also use a set widget to make the variables, I just like the list widgets for some reason.

hubertgk

unread,
Apr 3, 2018, 5:41:21 AM4/3/18
to TiddlyWiki
Thank you Jed for the specific examples. I knew how to substitute but wasn't aware of the 'inverse' syntax for the <$count> operation -- when noted as the <$count> widget I could never get it to work but putting it at the end of a <$list> filter as [count] does work exactly as needed.

Just for the record, here's my sample code -- by means of an example, this code returns a sum of tiddlers tagged as apples and oranges (so, 2 variables wrapped around the macro that's performing the calculation). The 'oranges' list still returns the full count as defined by its own filter, even though it's encapsulated within the 'apples' list filter. I guess that's because it's a count operation.

\define Calculation()
<<formula "$(apples)$+$(oranges)$">>
\end

<$list filter='[tag[apple]count[]]' variable='apples'>
<$list filter='[tag[orange]count[]]' variable='oranges'>
<<Calculation>>
</$list>
</
$list>

Thanks again!

Best regards,
Hubert
Reply all
Reply to author
Forward
0 new messages