$list filter with empty tiddler values - interesting behaviour to know

86 views
Skip to first unread message

S. S.

unread,
Apr 5, 2019, 7:18:16 AM4/5/19
to TiddlyWiki

When trying to test for an either/or parameter, I used a filter, and found this interesting behaviour:

\define test1(a b)
<$list filter="[[$a$]] [[$b$]] +[limit[1]]" emptyMessage="c"></$list>
\end
\define test2(a b)
<$list filter="[enlist[$a$]] [enlist[$b$]] +[limit[1]]" emptyMessage="c"></$list>
\end

!! Test 1
1. <<test1 a:A   b:B>>   <br>
2. <<test1 a:A   b:"">>  <br>
3. <<test1 a:""  b:B>>   <br>
4. <<test1 a:""  b:"">>  <br>

!!Test 2
1. <<test2 a:A   b:B>>   <br>
2. <<test2 a:A   b:"">>  <br>
3. <<test2 a:""  b:B>>   <br>
4. <<test2 a:""  b:"">>  <br>


Test 1

1. A
2. A
3.
4.

Test 2


1. A
2. A
3. B
4. c


Perhaps useful too keep in mind!

Cheers



Mohammad

unread,
Apr 5, 2019, 8:46:40 AM4/5/19
to TiddlyWiki
Hi S.S.,
 Thank you for sharing!
I don't understand the result of test 3 in two cases! Why they are different?

--Mohammad

Matthew Lauber

unread,
Apr 5, 2019, 9:18:35 AM4/5/19
to tiddl...@googlegroups.com
The difference is due to the enlist filter.  In the first test case, [[]] is parsed as a tiddler title with the empty string "" as it's value.  Weird, but it's still added to the input title list of the filter.  But in the enlist filter, it does string parsing to determine all the titles in the parameter, and it determines there aren't any in the param, so it doesn't add anything to the list of input tiddlers titles.

So, in
1-3: the filter looks like "[[]] [[B]] +[limit[1]]" which returns "" as it's value.  But in 
2-3: the filter looks like "[enlist[]] [[B]] +[limit[1]]" which reduces to "[[B]] +[limit[1]]" which returns "B" as it's value.

Mohammad

unread,
Apr 5, 2019, 9:22:19 AM4/5/19
to TiddlyWiki
Mat,
 I expect the macro test1 returns B for test 3, becuase while a param is empty but b has value and [[$a$]] [[$b$]] means OR
 Am I right?

--Mohammad


On Friday, April 5, 2019 at 5:48:35 PM UTC+4:30, Matthew Lauber wrote:
The difference is due to the enlist filter.  In the first test case, [[]] is parsed as a tiddler title with the empty string "" as it's value.  Weird, but it's still added to the input title list of the filter.  But in the enlist filter, it does string parsing to determine all the titles in the parameter, and it determines there aren't any in the param, so it doesn't add anything to the list of input tiddlers titles.

Matthew Lauber

unread,
Apr 5, 2019, 9:46:12 AM4/5/19
to TiddlyWiki
Two filter runs sequentially means {result of filter run 1} followed by {result of filter run 2} (dominantly appended I believe) which isn't exactly the same as OR.  The other thing is that [[]] isn't a false/invalid value, as far as filters are concerned.  So, the list generated is "[[]] [[B]]" which are both valid inputs to the following filter run.  And so [limit[1]] takes the first value passed to it, which is [[]].

Matt

Mohammad

unread,
Apr 5, 2019, 10:29:27 AM4/5/19
to TiddlyWiki
Thanks Matt!

I got the point!

Cheers
Mohammad

Mohammad

unread,
Apr 5, 2019, 10:29:53 AM4/5/19
to TiddlyWiki
Added to TW-Scripts with the explanation by Matt!

--Mohammad

On Friday, April 5, 2019 at 3:48:16 PM UTC+4:30, S. S. wrote:

LorenzGL

unread,
Apr 6, 2019, 12:32:57 AM4/6/19
to TiddlyWiki
Since I have the filter experts in this thread: I've been struggling with a somewhat similar problem that I have tried solving using the enlist operator... unfortunately without success. I have to accomplish the following task:
  1. While in TiddlerZ Read text from TiddlerA
  2. Remove a prefix from text to derive name of TiddlerB
  3. Look up a field value from TiddlerB
  4. Plug field value into another filter
My approach for solving this is essentially composed of 
  1. <$set name="fieldValue" filter="[[tiddlerA]removeprefix[prefix]get[fieldName]]">
  2. <$set name="filterInput" value="[listed<fieldValue>]">
  3. [subfilter[filterInput]...]
These steps do what they are supposed to do, however, they fail when the field value in Tiddler is referencing a tiddler with a space, e.g. [[FirstName LastName]]. In this case, the value gets parsed as "[[fieldValue]]" which then messes up the subsequent filters. Any tips on the proper way of dealing with bracketed Tiddler names (if using camel case is not an option)?

Thanks,

Lorenz

TonyM

unread,
Apr 6, 2019, 1:35:48 AM4/6/19
to TiddlyWiki
Step 2 filterinput is defoned as a variable.

Thus the final is [subfilter<filterinput>]

Regards
tony

S. S.

unread,
Apr 6, 2019, 2:06:29 AM4/6/19
to TiddlyWiki
As Tony pointed out, perhaps more on this line:

<$set name="fieldValue" filter="[[TiddlerA]get[text]removeprefix[prefix]]">
<$set name="filterInput" filter="[subfilter
<fieldValue>get[fieldname]]">

<$text text=<
<filterInput>>/>

</$set>
</$set>

Regards.

S. S.

unread,
Apr 6, 2019, 4:15:45 AM4/6/19
to TiddlyWiki

LorenzGL - it's always better to open a new Topic than change the subject of a running topic completely - as others will most likely not benefit from this discussion. It also detracts from discussion on the original topic.

Anyway, since this topic is already corrupted, I believe this also works:

<$set name="fieldValue" filter="[[TiddlerA]get[text]removeprefix[prefix]get[fieldname]]">

<
<fieldValue>>

</$set>


LorenzGL

unread,
Apr 8, 2019, 12:54:19 AM4/8/19
to TiddlyWiki
Sorry for hijacking the thread... thanks for your help. Will post the results in a separate thread so other's can learn from them, too.
Reply all
Reply to author
Forward
0 new messages