Closed kookma closed 9 months ago
NOTE:
From https://github.com/Jermolene/TiddlyWiki5/pull/7004#issuecomment-1287892029
Consider below code
\define parent()
\define child01()
This is child01. This is `$(var-from-parent)$`: $(var-from-parent)$.
\end child01
<$let var-from-parent="120">
<<child01>>
</$let>
\end parent
<<parent>>
It produces
This is child01. This is : .
Something goes wrong with parsing when substituion does not work!
Hi @kookma in the second example the variable substitution first takes place when <<parent>>
is invoked. At that point the values of the variables haven't been set, and so are not substituted.
At that point the values of the variables haven't been set, and so are not substituted.
Does this mean, one cannot use variable substitution from parent macro?
Does this mean, one cannot use variable substitution from parent macro?
I think the reverse: it will try to do the variable substitution to the first macro encountered. Macros contained within that one will therefore have the variable substitution markers removed.
Thank you! I keep this issue open to do more experiments.
It produces
This is child01. This is
: .
What about this? Note that
\define child01()
This is child01. This is `$(var-from-parent)$`: $(var-from-parent)$ ddddd
\end child01
will produce This is child01. This is : ddddd
which is not correct! everything by "\end" will parsed as code.
Hi @kookma I think it's the same issue: the textual subsitution of variables occurs at the first opportunity. Once it has happened, the markers are gone, and so it won't happen again if the same text is fed through a macro again.
These nested definitions are much more useful with the procedures and widgets of #6666, where there is no textual substitution occurring.
Thank you! Should I close this issue?
Hi @kookma perhaps we should address it via some documentation updates? I've added a very brief docs update to Macro Definitions in WikiText
but it might be worth pulling out a separate Nested Macro Definitions
tiddlers?
perhaps we should address it via some documentation updates?
Absolutely! TBH, for me this is confusing and just after your explanation I understood what is going on behind the scenes! So yes. I will be available for any test!
@kookma Just as an aside; tested your examples on tiddlywiki.com
In your first example, only if I remove the "text" following the two \end statements I get the expected result.
\define child01()
This is child01. This is $(var-from-parent)$
: $(var-from-parent)$.
This is child01. This is <<var-from-parent>>
: <
\define parent() <$let var-from-parent="120">
Call child01:
<
<
* In your second example I understood you could only define one macro in another if the inner macros were single line with no `\end`
So I restated the problem a little;
\define parent()
\define child01() This is child01. This is $(var-from-parent)$: <
<
and this works as expected, If I place the $let in the parent macro only (below the single line `\define child01` ) `<<var-from-parent>>` and worked `$(var-from-parent)$`. As with the let in the tiddler body, above, both work as expected.
Conclusions:
* Sub macros can only be one line ?
* `$(var-from-parent)$` is not valid when used in a a macro which is a sub macro regardless of where it is set.
Regards
Tony.
Hi @AnthonyMuscio it is not very clear but this ticket relates to the proposed \end <macroname>
syntax changes in #7004, and so the examples do not work on the prerelease.
@kookma -- Is this still an issue with v5.3.1?
No, the issue is not solved in 5.3.2
Interesting I never tried to nest the define but a parent procedure works;
\procedure parent()
\define child01()
This is child01. This is `$(var-from-parent)$`: $(var-from-parent)$.
<<var-from-parent>>!
\end child01
<$let var-from-parent="120">
<<child01>>
</$let>
\end parent
<<parent>>
Hi @kookma if we're talking about this code, then the reason why it doesn't work is that all the variable and parameter substitution occurs when the macro parent
is executed. Part of its execution is to define the macro child01
, but that definition won't be subject to any further parameter or variable substitution.
\define parent()
\define child01()
* This is child01. This is `$(var-from-parent)$`: $(var-from-parent)$.
* This is child01. This is `<<var-from-parent>>`: <<var-from-parent>>.
\end child01
<$let var-from-parent="120">
Call child01:
<<child01>>
</$let>
\end parent
<<parent>>
@Jermolene Thank you for clarification. While procedures replacing macros and recommendation is to not use text substitution, I think your explanation above worth to be added into official documentation.
From https://github.com/Jermolene/TiddlyWiki5/pull/7004#issuecomment-1287892029
Issue: Variable substitution from parent in child macros does not work.
Case i: Non Nested Macro Structure
The below WIkiText works.
Case ii: Nested Macro Structure
The below WIkiText does not works.
None of
$(var-from-parent)$
or<<var-from-parent>>
work.