On Tuesday, December 1, 2020 at 4:12:00 AM UTC-8 Nicolas Petton wrote:

> I would expect macros to be expanded recursively, before any parsing is 
> done on the string. It seems to be mostly the case, but I do not 
> understand the following. 
>
> If I define & use macros as 
> \define foo() 42 
> \define bar() <<foo>> 
> <span><<bar>></span> 
>
> The expansion works as I'm expecting it to, and the output is 
> <span>42</span> 
>
> However, if I use it as below: 
> \define foo() 42 
> \define bar() <<foo>> 
> <span class=<<bar>>></span> 
>
> Then the expansion yields 
> <span class="<<foo>>">test</span> 
>
> As if all of the sudden macro expansion wasn't recursive anymore. 
> I think I'm misunderstanding something :-) 
>

Macros only do 2 things:
1) replace instances of $param$ with the values passed into the macro
2) replace instances of $(param)$ with the values of variables defined 
outside the macro

Other than those two actions, the macro contents are simply "returned" for 
further processing in the calling context.  It is this context which 
determines what happens next.  If the macro occurs within wikitext (your 
first example), then the macro call is replaced by its output and parsing 
continues with the first character of the replaced content.  If that output 
contains a macro call (as in your example), then that macro is processed, 
and its contents are returned for further processing.  Thus, multiple 
layers of macro calls are *iteratively* expanded.  If a macro call *invokes 
itself*, then this is would be referred to as *recursive* expansion.

In contrast... if the macro call is used as a parameter value in a widget, 
then the macro call is replaced by its output as before.  However... all 
further processing is left to be handled by the widget itself.   This also 
applies when the macro output is used as a parameter value in HTML syntax, 
giving the results that you see in your second example.

If you want a widget or HTML parameter macro call to be iteratively 
expanded, then you can do this explicitly, by using the <$wikify> widget.  
Thus:
<$wikify name="myparam" text=<<bar>>>
<span class=<<myparam>>></span>
</$wikify>

-e

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/a910cfeb-adda-4a8a-9e39-06803e005207n%40googlegroups.com.

Reply via email to