I think this is why its proven difficult to understand what is going on @jypre, I am confident this explains the problems you have had.
This behaviour of \procedures
is identical to that of macros using \define
. As the documentation says they need to be wikified. If simply given as a parameter value they will return the “tiddlywiwiki script” contained within the macro, not the value you expect.
- Unfortunately this is not obvious because it’s kind of hidden from us. We just see it break.
- When used in wikitext
<<macroname
or <<procedurename>>
and for that matter <$awidget/>
they get “rendered/wikified” at the last moment as the result is displayed, and only then (unless you use wikify).
You can prove this by using <$text text=<<macro-or-procname>>
and you will see the result is not the wikified value, but the source tiddlywiki script.
With macros, and now procedures, the only way to make use of this is to first convert it to a variable, in a way, that first evaluates the wiki text. This method is using the wikify widget (which it is recommended to avoid)
The best workaround method is what I call “just in time wikification”. But “functions/filters” below, are much better.
<$wikify name=result text="<<procname params>>" >
<<result>> can now be uses as the value of a parameter eg `=<<result>>`
</$wikify>
I was disappointed that this was not resolved with the development of the new procedure, but I have now come to have some understanding of why this is the case. But it is hard to explain, it is to do with the difference, or lack of, between “macros” and “widgets”.
- You will notice how an attribute can’t be given a widget as a value, try it, it will not work.
- I believe macros and procedures are rewritten internally as $set widgets, so they may as well be widgets.
- I have come to realise that widgets are really only “display outputs”, although powerful ones. They can not themself be a value to an attribute.
Saved by the function/filter
However functions, whilst only able to contain filters, can be used as values to parameters, or used in subsequent filters without need of wikification, because they are first evaluated as a filter, before the call/value is used/takes place.
- functions by default only return the first value, this is all that is needed in many cases.
- you can get around this by using
+[join[]]
to turn the function result into a single string, you can also keep it as a full list of titles by using ...format:titlelist[]join[ ]]
you will later need to use enlist to extract all items from the value.
- Most things you would like a macro or procedure to generate and use, as the value to an attribute can be now be achieved inside a filter and using the new function/filter.
- These can also accept titles and parameters as their input, access other variables and fields/tiddlers.
- With a “.” in their name they can also be used as custom operators, so anything that could be written in a filter can be written in a function.
-
@saqimtiaz demonstrated elsewhere functions can even be used recursively, or in a nested way.