Is[blank] seems to return nothing

\define foo(element)
<$list filter="$element$ +[is[blank]]"> O{{!!title}}O </$list>
\end

(disregard the miscoloration from google)

Calling <<foo>> without an argument I was expecting this to return OO but nothing is returned. If I change is into !is also nothing is returned.

Docs for is[blank] reads:

blank | is blank (i.e. is a zero length string)

Why is there no output - neither for is nor !is? Bug?

Thanx!

The is[...] filter operator expects some kind of preceding filter run as input. However, when no $element$ argument is provided, the resulting filter syntax becomes just: +[is[blank]], which lacks any input; thus, no output is produced. To make your filter work, use:

\define foo(element)
<$list filter="[[$element$]] +[is[blank]]"> O{{!!title}}O </$list>
\end

The brackets around [[$element$]] ensures that even if the argument is omitted, the first filter run still produces a blank value (i.e., [[]])

-e

2 Likes

@EricShulman - thank you but this seems to contradict previous experiences where I’ve had to fight my intuition like in:

{{{ [[]] +[count[]] }}} which outputs 1

Maybe “blank” doesn’t mean “nothing” as I’m thinking it does?

Or maybe we simply define “blank” as “[[]]” in TW?

Would it make sense to propose to modify the is operator to accept a missing filter run as input? If not, how can the docs for the blank argument be modified to clarify that it is not really a matter of a “zero length string”?

We’re bordering on existential philosophy here. If we carefully remove all the cheese around the holes of the cheese… do we get only the holes left?

Lol! It is certainly true that philosophically “nothing” is often a “something”. In computer science some implementations would count it as “1” :slight_smile: as once counted it becomes more than nothing :-).

Just a comment, TT

TW filters do indeed make a distinction between “nothing” and “blank”:
“nothing” means no filter result, while “blank” means a result that is a “zero length string”

To test for “nothing” you can use count[]match[0]
To test for “zero length string” you can use is[blank]

There is a similar distinction made between a field that does not exist vs. a field that exists but is empty. This important difference can best be observed in the use of “has[fieldname]” – which is only “true” when a field exists and contains a non-blank value – as compared to “has:field[fieldname]” – which is also “true” if the field exists, but is empty. While both conditions indicate that “there is no value specified”, they arise from different underlying data and, depending upon the specific use-case, may call for different responses from the end-user.

-e

4 Likes

We have else operator to detect the empty output from previous filter run/step.

Here variations for your example will be:

\define foo(element)
<$list filter="$element$ +[is[blank]] :else[[]]"> O{{!!title}}O </$list>
\end

\define foo(element)
<$list filter="$element$ +[is[blank]else[]]"> O{{!!title}}O </$list>
\end

The $list widget has its alternative to when the filter output is empty, the emptyMessage attribute. But it replaces the full string of the content between tags of the $list widget.

1 Like

{{{ [[]] +[!is[blank]count[]] }}} output 0 so yes a blank value is still a value

1 Like