Exploring Procedures in 5.3.0

I am working hard to come to terms with the changes in TiddlyWiki 5.3.0, I am however now trying to understand the use of and features of procedures, especially in contrast to macros \define.

Consider this example;

\procedure myproc()
<$parameters name={{$:/SiteTitle}} desc={{$:/SiteSubtitle}}>
This is <<name>> demonstrates <<desc>>.

<<myproc [[aTitle]]>>
  • note if you change \procedure to \define it is inter-changable, the use of the new $parameters works in both, even if you don’t (name) your parameters.
    • This ability to not name parameters may prove useful, but how.
  • In procedures the parameters are available as variables ONLY
  • In a macro we can now still access the parameter using the form $param$ as long as it’s named in the macro parameters (but not in procedures).

I belive there are technical reasons to avoid the old substitution methods $param$ , and the new uses of the backticks is useful, but these are limited.

  • They only work as attribute values

The use of procedures needs to be considered alongside other 5.3.0 features like translations but transclusions are possibly a subject for another day.

Please help me !

  • Help me understand any features, I have missed and what is the key use of procedures?
  • How best do we start doing concatenation in procedures?.
  • How best will we deal with text that is camel case in parameters with procedures? (and the old macros for that matter),
    • must we still use the $text widget?
  • If there are performance issues or some other problem with using old macros can we please find a simple and accessible way to describe under what circumstances they should be avoided and why.
    • This will also help us decide when to refactor existing code.

For some reason, the documentation on procedures does not mention $(this syntax)$ with parentheses and dollar signs, which is called Substituted Attribute Values, which works more like the $param$ syntax of macros.

In my use-case, I was trying to make a macro/procedure/widget/whatever to produce links to English Wikipedia. I’ve come up with the following:

\procedure enwiki(title)
<a href=`https://en.wikipedia.org/wiki/$(title)$`>

This feature is not due to the procedures except in so far as named parameters are made into variables. Access to the variable is then given by the backtick attributes format.

I don’t understand what you mean. I also linked the page “Substituted Attribute Values”.

I meant that the documentation on procedures uses only <<syntaxWithAngleBrackets>> for parameters. Here are the all examples of usage of parameters in procedures, which I could find on tiddlywiki.com.

  1. \procedure my-procedure(parameter:"Default value")
    This is the procedure, and the parameter is <<parameter>>.
  2. \procedure say-hi(name,address)
    Hi, I'm <<name>> and I live in <<address>>.
    <<say-hi name:"Bugs" address:"Rabbit Hole Hill">>
  3. <div class=<<myclasses>>>
  4. \procedure my-procedure(param)
    This is the procedure text (param=<<param>>)

None of the examples use $(substituted attribute values)$, even though using Substituted Attribute Values is important for some kinds of procedure definitions

Substituted attribute variables are another feature altogether a feature we can make use of because the parameters are stored as variables. I suppose we could link to them from the procedure documentation. We could also link to the parameters widget.

We could give another example, it is however nessasary to draw the line somewhere between defining the features and demonstrating them in combinations.

You’re right. This is a “surfacing issue”. It’s not easy to find this info when you’re not even sure what to search for.

In defense of TW, the documentation grew organically. This topic might have been written differently if macros and procedures along with parameters (and other attrs/variables) came along together and at the same time.

The title of Substituted Attribute Values is not something any new user is going to search for. I remember stumbling across it and wondering why I hadn’t seen it before – I posted about it too but I don’t recall where or when. But I certainly thought it didn’t belong under such a quirky, off-the-beaten-path title.

In a similar vein, you might want to check out https://tiddlywiki.com/#substitute%20Operator.

1 Like

I believe procedure is faster to run, because it provides less feature.

I always mis-remember this as template string literal! Hope it have a better name.