Eric,

Nice to see your use of vars and filtered transclusions here, I really 
dislike the need to wikify, It took me ages to work out when I must and 
when not. Your approach seems a nice alternative.

If however some one is using wikify the name is reusable, and a little 
easier to read.

\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>

Just a simplification of one the of the forms.

Tones

On Wednesday, 14 October 2020 20:55:03 UTC+11, Eric Shulman wrote:
>
> 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 a macro that invokes 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: use $vars with "filtered transclusion" instead of $set 
> with filter param
> <$vars qty={{{ [all[current]tagging[]butfirst[]count[]] }}}>
> <$vars loc={{{ [<qty>compare:number:gt[1]then[several]else[single]] }}}>
> got <<qty>>: <<loc>><br/>
> </$vars></$vars>
>
> Simplification #2: if you don't need the "qty" value, combine all the 
> filter syntax
> <$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 
> entirely:
> {{{ [all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[
> several]else[single]] }}}
>
> enjoy,
> -e
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/2df94bae-cf7c-4859-a9cb-13e502ebfa6co%40googlegroups.com.

Reply via email to