<all> is not all[] and default function first operand

From previuous tiddlers I understood that in a filter .myfunction[] is equal to <.myfunction>.

And then I thought that it would mean that all[] would be the same as <all>. Which is not the case, but this is a little bit annoying that our beloved syntax as such discrepancies.

Whtever, in fact, my concern was about a filter function argument. I can code easily for “take the default input, but if it is void take the parameter, but if itself is void, take the current tiddler” as initial input. (by void, I mean satisfying is[blank]:

\define myfunction(arg) [all[]!is[blank]else<arg>!is[blank]else<currentTiddler>.doYourWill[]]

But what if I want “take the parameter, but if it is void take the default input, but if itself is void, take the current tiddler” as initial input?

I can’t build that with the same logic, if only beacause it would alter the default input! Instead, I wish I could code it like that.

\define myfunction2(arg) [all[]unless<arg>!is[blank]else<currentTiddler>.doYourWill[]]

where unless would swap the input with its argument if tha latter is not blank. This filter operator would have to be coded in javascript. I can do that, this is not my question.

My question is: would other people be interested in such a filter operator?

Do you see a way to achieve the same behaviour that could be coded withou that new filter operator?

I’m struggling to grasp the use-case without a little more context, but focusing exclusively on this part…

… it seems to me that you could just rearrange your filter a bit and do something like

[<arg>!is[blank]] ~[all[]] ~[<currentTiddler>] +[.doYourWill[]]
1 Like

This isn’t strictly true.

  • .myfunction[] = function[.myfunction]]
  • <.myfunction> = .myfunction[]first[]

To illustrate this, try the following example:

\function .myfunction() [tag[HelloThere]]

<$list filter="[.myfunction[]lowercase[]]" />

<$list filter="[function[.myfunction]lowercase[]]" />

<$list filter="[<.myfunction>lowercase[]]" />

<<.myfunction>>

I wouldn’t call this a discrepancy even if .myfunction[] did equal <.myfunction>, because all isn’t a function, it’s a filter operator. A function isn’t fundamentally a filter operator; fundamentally, it’s a special way to define a variable. A function can also be used as a custom filter operator if it contains a period—which specifically differentiates it from the core operators, which don’t contain periods and aren’t variables.

You could argue that we should have an <<all>> variable, but I’m not sure what it would do, because a variable’s value is normally a single string, not a list (which is why we need workarounds like +[format:titlelist[]join[ ]] to convert a list to a single string that can be preserved in a variable). Logically I suppose that would make <<all>> = [all[]first[]], but that feels contrary to the normal meaning of “all”.

5 Likes

To define functions, you need to use \function my.function(something)\define will not work. See [the docs](https://tiddlywiki.com/#Functions:Functions%20[[Pragma%3A%20\function]]%20[[function%20Op
erator%5D%5D)

The \function f.test() [tag[HelloThere]] definition is similar to assigning a transclusion list {{{ }}} to a variable, except functions always return plain text.

\function f.test() [tag[HelloThere]] 

<<f.test>>

----

<$let variable= {{{ [tag[HelloThere]]  }}}>

<<variable>>

@pmario Yes, I did the error on this topic, not in my code.

It,s just that in many other langauge, define would define a function: this is just an error lurking in the dark. :slight_smile:

@etardiff Yes, this is the idea. Many thanks!!! However, the !is[blank] test shall not be forgotten or the ~ won’to work as intended.

Here is a real life example with tests:

`
\function .partPrefix(part) [!is[blank]] ~[all[]!is[blank]] ~[] +[regexp[^\w+::\d]split[::]first[]else[no-prefix-because-not-part-like]]

  • with input as LUCK::3.14
    ** void here: {{{ [[LUCK::3.14].partPrefix[]] }}}
    ** for TEST::2.71 e: {{{ [[LUCK::3.14].partPrefix[TEST::2.71 e]] }}}
    ** void in TEST::3.14 Rounded Pi: <$tiddler tiddler=“TEST::3.14 Rounded Pi”>{{{ [[LUCK::3.14].partPrefix[]] }}}</$tiddler>
  • with blank input
    ** in TESTING::3:14 Pi: <$tiddler tiddler=“TESTING::4.14 Pi”>{{{ [[].partPrefix[]] }}}</$tiddler>
    `

ouput:

  • with input as LUCK::3.14
    • void here: LUCK
    • for TEST::2.71 e: TEST
    • void in TEST::3.14 Rounded Pi: LUCK
  • with blank input