\define countTaggedBySelf() <$count filter="[all[current]tagging[]butfirst[]]"/><$set name="qty" value=<<countTaggedBySelf>> ><$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">got <<qty>>: <<loc>><br/></$set></$set>Then I get "got 2: single" ??? (in a tiddler where the countTaggedBySelf has sense and returns 2.)But if I write instead<$set name="qty" value=2 >
\define countTaggedBySelf() <$count filter="[all[current]tagging[]butfirst[]]"/>
<$wikify name="qty" text=<<countTaggedBySelf>> >
<$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$wikify>
<$set name="qty" filter="[all[current]tagging[]butfirst[]count[]]" >
<$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$set>
<$vars qty={{{ [all[current]tagging[]butfirst[]count[]] }}}>
<$vars loc={{{ [<qty>compare:number:gt[1]then[several]else[single]] }}}>
got <<qty>>: <<loc>><br/>
</$vars></$vars>
<$vars loc={{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] }}}>
got <<loc>><br/>
</$vars>
{{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] }}}\define qty() <$count filter="[all[current]tagging[]butfirst[]]"/>
<$wikify name="qty" text=<<qty>> >
<$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$wikify>On Wednesday, October 14, 2020 at 2:09:57 AM UTC-7, Jean-Pierre Rivière wrote:\define countTaggedBySelf() <$count filter="[all[current]tagging[]butfirst[]]"/><$set name="qty" value=<<countTaggedBySelf>> ><$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">got <<qty>>: <<loc>><br/></$set></$set>Then I get "got 2: single" ??? (in a tiddler where the countTaggedBySelf has sense and returns 2.)But if I write instead<$set name="qty" value=2 >Macros do *not* "evaluate the syntax and return the output"... they just do substitutions for $param$ and $(variable)$Thus, countTaggedBySelf() does not return a number, it returns: <$count filter="[all[current]tagging[]butfirst[]]"/>and the subsequent <$set name="qty" ...> also just sets the qty variable to: <$count filter="[all[current]tagging[]butfirst[]]"/>There are several ways to fix this:Method #1: use <$wikify> to convert the <$count> into it's actual number:\define countTaggedBySelf() <$count filter="[all[current]tagging[]butfirst[]]"/><$wikify name="qty" text=<<countTaggedBySelf>> >
<$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$wikify>Method #2: use the [count[]] filter instead of the $count widget:
<$set name="qty" filter="[all[current]tagging[]butfirst[]count[]]" >
<$set name="loc" filter="[<qty>compare:number:gt[1]then[several]else[single]]">
got <<qty>>: <<loc>><br/>
</$set></$set>
Simplification #1: if you don't need the "qty" value, combine all the filter syntax<$set name="loc" filter="[all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]]">
got <<loc>><br/>
</$set>Simplification #2: use $vars with a "filtered transclusion" instead of $set
<$vars loc={{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] }}}>
got <<loc>><br/>
</$vars>
Simplification #3: if you just want to display the result, skip the $vars (or $set) entirely:
Thank you Eric. Once again, I stumble upon the terrible rule "macro do only text substitution". I know it, but I have not yet realized all what it means. I selected the wikify approach of method #1 as I want to keep using the countTaggedBySelf macro to avoid duplicating code.Simplification #3 creates a link, which is not wanted. Is there a similar quick notation to just get the raw text instead of an internal link? Note that is why I created my macro with the count widget inside.
<$text text={{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] }}}/>{{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] }}}<$text text={{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] }}}/><$text text=<<currentTiddler>>/>{{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[several]else[single]] || (text) }}}
{{!!fieldname}}{{{ filter }}}<<varname>>even<<macroname parameter>>works\define macroname(param) The Macro Output <<transclusion>> with $param$
{{!!working}}+{{!!fieldname}}{{{ [<currentTiddler>removeprefix[New]] }}}<<transclusion>>even<<macroname parameter>> works