Macros, when made global with a tag such as $:/tags/Macro are actually quite sensible and allow you to invoke something where you want in your text, with that something, “the details”, not visible. “Write once, use many times”, you could say.
I have a tool in the view template which scans the fields on the current tiddler, looking for those fields who’s value begins with a prefix of a protocol eg http https. If one or more is found it presents them above the body text in this form;
Another way to look at macros is simply, reusable content, if in one tiddler you are going to use the same wikitext, with or without parameters, more than once, then define a macro in that tiddler.
If you will need to use it in many tiddlers make a global macro.
Yes, thank you. I do make significant use of macros already. Here it was a single template (applied to multiple tiddlers) and I was frustrated in many attempts to make it work. I can’t recall all the iterations I went through, although I’d swear I tried one of your suggestions below to no avail. Eventually, I gave up and wrote a macro. I just assumed that I was missing something basic.
Oh, yes, I looked this up and noted that it wouldn’t seem to handle a field.
I swear I tried this and it didn’t work. It was the first thing I did (without the class or rel attributes) and then I started digging into more arcane ideas. I’m going to have to go back and check it again.
Yes, this is a very familiar concept for a programmer. The hardest problem is to remember to avoid thinking of macros as functions. It’s a terribly easy mistake.
Because in a way using a template is reusable code, just as macros are (and can include macros).
If this is the case;
Then we want to write wikitext that refers to the current tiddler. It is hard coded in the template, not the tiddler.
You can use this directly in the “view” and other templates;
<a href={{!!wikipedia-link}} class="tc-tiddlylink-external">More info from wikipedia</a>
The current tiddler is implied before the !!
or this
<$list filter="[all[current]has[wikipedia-link]]" variable=~>
<a href={{!!wikipedia-link}} class="tc-tiddlylink-external">More info from wikipedia</a>
</$list>
or just {{!!wikipedia-link}}
and other forms,
What do you mean by this? I don’t seem to have this problem. “macros is macros”.
There are many ways and tangents to answering your initial topic, with all due respect, I suspect you are missing a particular concept, or cognitive model (or I am about your words ).
I faced a number of these cognitive hurdles learning tiddlywiki myself. Once overcome they are incorporated into your thinking and you forget they were ever an issue. So they are hard to “share” with others.
If we can document these they would be “documentation gold”.
Think of a macro reference (don’t think of it as a “macro call”) as a meta-programming instruction (a pre-rendering instruction) to replace the reference with the snippet of text defined by that macro.
It is just a form of transclusion that is almost like a “mail merge.” The snippet of text defined by the macro is like a standard form letter, and the parameters are like the individual addresses.
That helps me get my thinking straight. I sure hope it doesn’t confuse the daylights out of anybody else !
Right, I know that intellectually, but I still continually want them to act like functions, and for wikitext to act like a programming language when it’s really a (very sophisticated) markup language. I’ll get there eventually, I’m sure, but it sometimes seems frustratingly slow.
I’ve heard enough other discussions here to know that this seems to be a common problem with programmers learning TW. I get that, but it doesn’t really ease the pain.
Thanks for your reply. It’s good to know others have gone through this too.
The {{||tBib}} transclusion will show the title of the book followed by a little link to the Internet Archive (or whatever source; at the moment, I’m only linking to the internet archive).
The tBib template tiddler (Some of my tiddler titles have suffixes which I precede with a unicode “#” character. I filter out that suffix for displaying.)
Yes, sorry if I didn’t make that clear. My fundamental question has been answered aptly by you and by several others. No: that is not the state of the art. It’s overcomplicated. For some reason, it seemed that everything else I tried that wasn’t a macro call from a template was failing. But one of your solutions did exactly what I wanted to without that macro, and with simpler code than I had written so far.
A section of GrokTiddlyWiki describes this well. I’ve reread it multiple times but it clearly still hasn’t sunk in. For me a function is a callable bit of code that at runtime offloads some of the common work into one place. A macro instead (and I’ve use LISP-style programming languages which have powerful macro systems) simply imports a chunk of work into your current workflow. These are distinct, but related processes.
I get the impression that this cognitive problem is one that affects many programmers trying to learn TW.
Oh, I’m quite certain that’s the case. I describe my problems as being confused by syntax, but I know that truly it’s fundamental concepts I still don’t have down.
Over time, “regressing” (i.e. the semantic meaning of macro falling back to the meaning in some non-TW context) becomes far and fewer between.
The most important thing you can do is banish the term “macro call” and “macro calling” from your vocabulary and communications/notes/whatever about TiddlyWiki.
Find alternative terminology that reminds you best what TW macro is and does. For me, it is “macro reference” (which reminds me, strangely, of macro substitution/transclusion).
Interestingly for me, an given I have used a range of macros over the years, inside Microsoft OS and applications, command line coding, keyboard macros etc… when someone says macros I ask “what kind?”.
One day I came across “tiddlywiki macros”, and whilst I had some preconceptions of macros, I quickly lost that, and since then I have learned “TiddlyWiki Macros” are their own thing.
For some reason when people say things like “TiddlyWiki Macros are not real macros, functions or like programming”, or are “a (very sophisticated) markup language” etc… I get a little agitated,
I am not agitated with the person (they are after all just, trying to understand and need to “see it” based on the axioms they are familiar with) but agitated that these descriptions, are ultimately miss leading. I feel like stepping in and putting a nuanced argument, that the “statement is not quite correct”. But then it would be like arguing against shadows, the shadows being peoples “transient rationalisations”. So I let those statements stand unchallenged.
My agitation comes from the fact there remains a lot of different “conceptualisations out there in the community”, many of which are not quite right, but necessary on their journey, but in many ways, nothing can be done about that.
I expect some of my “conceptualisations” are wrong too.
Macros are a type of programming construct that are used to generate code at compile time. Macros are a feature of many programming languages, including C, C++, and Lisp.
The main difference between macros and other coding is that macros operate on the source code itself, while other coding constructs operate on the runtime environment. Macros allow you to manipulate the code before it is compiled, while other constructs are used to manipulate the program’s behavior during runtime.
In other words, macros are a way to programmatically generate code that is executed at compile-time, while other coding constructs are used to generate code that is executed at runtime.
Macros are often used to automate repetitive tasks or to generate code based on complex rules or patterns. They can be very powerful, but they can also be difficult to use correctly. Macro code can be difficult to read and understand, and can be prone to errors if not used carefully.
Overall, macros are a specialized type of programming construct that can be very useful in certain situations, but they require a good understanding of the programming language and careful use to avoid errors.
Reading this you see perhaps where the confusion comes from ;
TiddlyWiki is not compiled at all
In some ways it is not even interpreted
It is ultimately “rendered”, in keeping with it as markup.
It kind of has two runtimes, as the wikitext, widgets and macros are parsed, then a final parsing of that result into HTML.
Then to make it just a little more mind blowing changes are propagated throughout the whole wiki with an efficient “only refresh a minimum” mechanism.
To me, the biggest problem with macros in TiddlyWiki is the documentation titled “calling macros”.
There is nothing being called. (That phrasing just triggers “call a function/procedure” thinking.)
I just want to point out that it was not TW macros but wikitext that I described as “a (very sophisticated) markup language”. Maybe that will reduce your agitation a bit.
And I don’t think people are saying that TW macros are not real macros. They are very much akin to macros in C and in LISP. But for whatever reason (perhaps because there are no functions or procedures (or are they coming with parameterized transclusion?), some programmers latch onto them as the closest thing available. They overlap with function execution, but they are most definitely not the same.
I know the feeling. I’m a fairly senior-level programmer, and do a lot of training an mentoring, and it’s difficult to know when to go beyond, “Yes, that’s the general idea…” to “Sure, but technically, you also need to consider…”
I usually struggle quite a bit here before I ask questions. In the background, I’m also starting to work on my own TW documentation, meant for people who think like I do. I won’t be ready to share it for some months, but I hope it will be a useful resource. It’s not the sort of thing that would fit into the main TW page, but maybe parts of it will make it in there. Maybe, if all goes well, it can help the next programmers who come along with similar issues to mine.
I haven’t tried ChapGPT yet, but I’m reasonably impressed with this answer. I think it’s fairly accurate, especially the first two paragraphs. The last two sound more attuned to C/C++ than the other, more powerful and yet still more intuitive, versions in something like LISP. But the important point here for TW is the distinction between source code and runtime. The closest TW has to a runtime is rendering/rerendering, and I keep finding myself thinking of Macros operating during this, when in fact they happen earlier.
I’d argue that. Compilation is the process of converting from one language to another, usually from a higher-level language to a lower one. I think the wikitext → HTML/DOM transformation can reasonably be called compilation.
I personally do not like calling “WikiText” the whole gamut of features in TiddlyWiki.
I can’t help but consider, because it makes more sense to my big picture: “WikiText” to me is just the Tw-markdown, the non-visual widgets are Tw-script, the visual widgets are Tw-Gadgets (or Tw-Controls), and filtering operations are Tw-QueryLanguage (TwQL), and then TwPragmas (the meta stuff.)
I can’t explain it, but the clear delineation is very calming/soothing for me. Otherwise, I have the same kind of anxiety as the kid who doesn’t like the mashed potatoes touching the peas…
I did read through and understand your tBib template. Thank you for sharing. I had one quick question. I understand nth, and in fact often name a function that for a similar purpose. But using it without a parameter, as nth[], seems to be a much less explicit way of writing first[]. Does it offer any advantages over first[]? Did it simply predate first[]? Or am I misunderstanding your usage here?