Perhaps surprisingly, this works perfectly fine:
\function circle-area(radius) [<radius>.radius-to-area[]fixed[2]]
\function circle-circumference(radius) [<radius>.radius-to-circumference[]fixed[2]]
\function .radius-to-area() [.square[]multiply<pi>]
\function .radius-to-diameter() [multiply[2]]
\function .radius-to-circumference() [.radius-to-diameter[]multiply[2]multiply<pi>]
\function .square() [power[2]]
\procedure pi() 3.1415926
<$list filter="1 2 3" variable="r">
<li>
Circle with radius <<r>>
<ul>
<$list filter="area circumference" variable="measurement">
<$let
funcName=`circle-$(measurement)$`
>
<li>
<<measurement>>:
<$transclude $variable=<<funcName>> radius=<<r>>/>
</li>
</$let>
</$list>
</ul>
</li>
</$list>
- area: 3.14
- circumference: 12.57
- area: 12.57
- circumference: 25.13
- area: 28.27
- circumference: 37.70
This is OK because TiddlyWiki reads all the pragmas in a tiddler prior to doing anything with their contents them. While the pi
variable, for example, isn't defined until after all of the functions that use pi
are, that's OK because TiddlyWiki still hasn't actually evaluated any filters yet. It's only once all the pragmas have been read and their names added to the current scope that TiddlyWiki starts actually parsing the wikitext of the tiddler, sees function calls, and tries to run the filters inside the functions. So by the time TiddlyWiki tries to use the name pi
, it's fully defined.
It's still good practice to try to define functions and procedures roughly “in order”, with those that depend on earlier ones later in the tiddler, simply because this makes it easier to find the one you're looking for when you read through the tiddler later.