I’m trying to understand the relationships between the different methods of substitution in TiddlyWiki.
I need to be confidently able to manipulate variables. Variables are the fundamental units of information that get rendered from one place to another. Most things in TiddlyWiki are actually variables.
- Procedures are variables:
Procedures are implemented as a special kind of variable. The only thing that distinguishes them from ordinary variables is the way that the parameters are handled. ~ #Procedures
- Functions are variables. ~#Functions
- Macros are variables. ~#Macros
I understand that the angle bracket syntax denotes references to variables. In general, double angle brackets mean that some kind of variable is being rendered into the tiddler.
When I consider the problem of constructing strings from references to different tiddler data, I can’t fathom any way to do this other than by constructing a variable using procedures, functions, or macros. I’m pretty sure there’s another way to do this. I think you can transclude into variables somehow, but I can’t figure out how. I had a breakthrough last night when I realized that the reason why I’m struggling so much with TiddlyWiki is that I don’t understand functional programming structure. I think TiddlyWiki is a nearly pure functional programming environment. It is not very procedural and not very object oriented.
I think I have to construct my variables and I think the reason I think this is because I don’t know how to think some other way.
In my student project, I’m experimenting with functions and procedures because I need to construct strings using tiddler fields and filters. I want to post a difference in behavior between procedures and functions.
So, I go to the top of my tiddler and define function:
\function slug()
<$parameters tiddlerTitle={{!!title}}>
[<<tiddlerTitle>>split[—]first[]]
</$parameters>
\end
There are widgets, transclusions, and content in that tiddler. And then, somewhere in all the contents of the tiddler, I call the function by using the basic <$text> widget:
<$text text=<<slug>>/>
The output is the text “<parameters”.
What if I change the function into a procedure?
\procedure slug()
<$parameters tiddlerTitle={{!!title}}>
[<<tiddlerTitle>>split[—]first[]]
</$parameters>
\end
That outputs the whole <$parameters> widget.
That’s really intriguing:
- Maybe the parameters widget isn’t supposed to be used in procedures as in functions.
- The docs say that the parameters widget must be used “when the default value of a parameter must be computed dynamically”
- It also says that the parameters widget defines variables for the transclude widget, the underlying mechanism, which “dynamically includes the content from another tiddler or variable”.
The reason that I tried <$parameters> inside the function/procedure experiment is that I can’t figure out how to substitute into the function/procedure/macro. I mean, I think I know syntactically how to do so, although the curly-brace transclusion syntax often confuses me. I’m pretty sure I’m radically over-thinking it, and I realized that the reason I’m overthinking it is that this kind of thinking is foreign to me.
Also, I suppose that widgets are actually “functions” in the sense of functional programming, i.e., in the sense of functions defined with Python’s “def” statement. (Of course, semantically within TiddlyWiki terms, functions are variables, as noted above, as clearly stated in the documentation.) I say this because widgets control substitution of data into other contexts where it does other things. I suppose that TiddlyWiki funtions and procedures allow some more procedural logic to be used in TiddlyWiki by allowing expressions to be directly built.