# Parameterised Transclusion [TW 5.3.0]: Why is Function Called Function?

``````\function .f(date) [!is[system]]:filter[get[created]split[]first[4]join[]compare:number:gt<date>]
``````
• Now in any tiddler you like invoke `.f.` function (it is a user defined filter operator)

Example i:

``````<<list-links "[.f[2022]]">>
``````

returns all tiddlers created after 2022

Example ii:

``````<<list-links "[.f[2014]limit[5]]">>
``````

returns tiddlers created after 2014, limits the output to first 5 outputs.

Example iii:

``````<<list-links "[.f[2015]tag[Concepts]]">>
``````

returns tiddlers created after 2015 and are tagged with `Concepts`.

So donâ€™t you think function is function ?

Add your more examples here! Or explain what other functions you like to have.

I think function allow us to do a little of what developers do, but for us without JS knowledge.

## More Examples

Write a function to returns sum of a series of number

``````\function mysum(t) [enlist<t>sum[]]
``````

Then use it like below:

``````<<mysum "1 2 3 4 5 -10 25">>
``````

returns

30

Note you can make your function global by putting it inside a tiddler tagged with `\$:/tags/Macro`

If your tiddler has a field called `cost` and contains `1 2 0 -6 12` then

``````<\$text text={{{ [function[mysum],{!!cost}] }}} />
``````

returns 9

4 Likes

You know why `function` is called `function`? Because itâ€™s recursive!

1 Like

That confuses me.

Isnâ€™t a macro recursive?

If a macro is recursive, then whatâ€™s so special about a function that it is named as such because it is recursive?

As I understand it (which is not too well) thatâ€™s the bulk of what v5.2.3 is all about.

1 Like

Hi @Charlie_Veniot
Function is different from macro!

Hi @Scott_Sauyet
I believe TW 5.3.0 makes wikitext scripting more powerful.

More important have a look at below tables created by @btheado

1 Like

That has no bearing at all with the context of the post I replied to and does not answer my question.

That depends on perspective.

Well, here I tried to give examples of using functions like other programing language e.g `y=f(x)`. I think the #6666 PR gives good discussion on functions and the table by Brian (https://github.com/Jermolene/TiddlyWiki5/pull/6666#issuecomment-1287951571) is a good point to understand the difference between macro/ and function.

Still not answering my question.

Perhaps not. If it allows the user to do something with wikitext that previously could only be done in JS, then it is objectively more powerful. That is not a value judgment; I do know that youâ€™re not happy with the recent direction of TW, but this is not about that. It just about what sorts of features the syntax supports.

Yes, a macro is recursive.

It isnâ€™t related to recursiveness.

A function is a named snippet of text containing a Filter Expression. Functions can have named parameters which are available within the function as variables. Functions allow to create new user defined filter operator (if their name start with `.`)

1 Like

While I canâ€™t speak for Mark, Iâ€™m pretty sure this was meant as a joke: something about using the word â€śfunctionâ€ť in the definition of â€śfunctionâ€ť associates the concept with recursion. Itâ€™s not all that funny, partly because it doesnâ€™t really match the way, say, â€śrecursion (n). See recursion.â€ť does.

So this holds no answer to how that makes it different from a macro.

I did read the overview that explained the differences, but I was still too new to TW to understand them. I mostly came away with the impression that they allowed some things only possible before with custom JS. I may have that wrong, though.

1 Like

Something may be considered more powerful by the majority, but it is not right to say it is more powerful for all.

For every new/changed feature, there is a cost. For a person who sees the cost as outweighing the benefit, then there is less power for that person.

The trade-offs may mean more power to many, but it doesnâ€™t mean more power for all.

It is all about perspective. Market the latest version as more powerful, thatâ€™s fine. It should be okay for me to know it isnâ€™t right for me and say as such when somebody throws at me that I should see it as more powerful.

Iâ€™ll only ever bring it up when somebody throws that at me. I wasnâ€™t complaining about the latest version of TW.

I just had a simple question I was hoping somebody could answer.

I donâ€™t care about that.

All I wanted to know was what the recursion thing meant. As if it was something special about functions.

Scott,
Well I am happy to see new features in TiddlyWiki and I think it is good to be able to write wikitext script which are simpler to understand and easier to maintain.

The good point with TiddlyWiki is you can choose your own subset of core features and add your custom tools (Macros, Styles, Templates,â€¦) to create favorite editions. Its always backward compatible, so you can simply ignore any new feature you may not like it.

So, I belive TiddlyWiki 5.3.0 is a very good step forward.

2 Likes

I only wanted to know what Mark meant about recursion.

It sounded like functions had something special over macros in regards to recursion.

Iâ€™m sorry you are replying to me with all of this info about functions when Iâ€™m not interested in any of it; all I was interested in was the very focused topic of â€śrecursionâ€ť macros vs functions.

I was just saying that â€śpowerfulâ€ť here is not a subjective term, but something with a clear-cut objective definition. If system B has all the features of system A, but also some additional capabilities that A does not have, then itâ€™s technically more powerful.

That it might also be more muddled, more difficult to learn, less useful to most users is a separate issue altogether. A system can be more powerful and totally unusable.

If 5.3.0 allows us to do thing with wikitext that we couldnâ€™t do in earlier versions, then that by itself makes it more powerful. (Technically it makes the wikitext subsystem more powerful. TW as a whole is not likely to get more powerful, as youâ€™ve always been able to descend to the JS layer, and that isnâ€™t changing here.)

Programming language nerds use this distinction frequently. But Iâ€™m sorry I brought it up, as I donâ€™t think it added much to the conversation.

2 Likes

As I said, Iâ€™m pretty sure that was just a weak joke, and youâ€™re trying to get an explanation for something no one was seriously implying.