Inputting a function into a function

The new function and procedure pragmas are great and fun (ha), and I’ve been experimenting around with them until I reached this:

\function AddTwo(number)
[<number>add[2]]
\end

\function Multiply(number1, number2)
[<number1>multiply<number2>]
\end

<<AddTwo 2>> == 4

<<Multiply 4 4>> == 16

<<Multiply <<AddTwo 2>> 4>> == 0

This happens because the call interpreted entire <<AddTwo 2>> as a single string, which gets converted to 0.

I’ve tried several variations like <<Multiply [[<<AddTwo 2>>]] 4>>, but I was unable to get it to work as I wanted (where the output of AddTwo is input into Multiply's parameter).

How could you make this work? I bet you could do something with the $transclude widget, but that’s considerably more clunky to use imo.

1 Like

You cannot nest short form macro calls. You are right, in that you have to use the transclude widget for the first call:

<$transclude $variable="Multiply" number1=<<AddTwo 2>> number2=4/>
1 Like

There are other ways to achieve the same result, yes you can use a function as if it is a macro to get its result but it also a filter, and its possible to combine filters. Also by default filters respond to the current title.

It is not possible to nest macros or variables like this <<Multiply <<AddTwo 2>> 4>>

Your could just use native filter operators;

All these examples work and should help your understanding;

\function add.value(value) [add<value>]
\function multiply.value(value) [multiply<value>]
\function multiply.values(value value2) [<value>multiply<value2>]

;Just strait filters
{{{ [[2]add[2]] }}}
{{{ [[4]multiply[4]] }}}
{{{ [[2]add[2]multiply[4]] }}}

;Now use a function

{{{ 2 +[add[2]] }}}
{{{ [[2]add[2]] }}}
{{{ 4 +[multiply[4]] }}}
{{{ 2 +[add.value[2]multiply.value[4]] }}}
{{{ [multiply.values[2],[4]] }}}
1 Like

I found this doc tiddler most enlightening when trying to figure out the (new) variable syntax:
https://tiddlywiki.com/#Variable Usage

Functions, procedures, etc. are all just different forms of variables.

Yaisog