This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Ex:CircleMathRearrangement/answer

 31st August 2024 at 5:24pm

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>

  • Circle with radius 1
    • area: 3.14
    • circumference: 12.57
  • Circle with radius 2
    • area: 12.57
    • circumference: 25.13
  • Circle with radius 3
    • 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.

    Go to question: Ex:CircleMathRearrangement