Macro Parameters & Quotes: Macros v Variables

50 views
Skip to first unread message

Louis Davout

unread,
Dec 24, 2021, 9:33:47 AM12/24/21
to TiddlyWiki

I just discovered something that was inhibiting my understanding of TW. It's probably somewhere in the docs and I either missed it or forgot it. But it might help someone else in the future.

In context of being a parameter, macros and variables behave differently from each other when enclosed in quotes.

If macro parameter is set to a variable that is not surrounded by quotes, variable is evaluated as expected. (A below).

If macro parameter is set to a variable that is surrounded by quotes, variable is not evaluated. (B & C below).

If macro parameter is set to a macro, that second macro is expanded regardless of quotes (D, E, F below).

```
\define mac(mac_param)
<$text text="$mac_param$"/>
\end

\define mac2(mac_param) MMM: $mac_param$

<$set name="var" value="VVV">
A: <$macrocall $name="mac" mac_param=<<var>>/><br>
B: <$macrocall $name="mac" mac_param="<<var>>"/><br>
C: <$macrocall $name="mac" mac_param="""<<var>>"""/><br>
D: <$macrocall $name="mac" mac_param=<<mac2 "AAA">>/><br>
E: <$macrocall $name="mac" mac_param="<<mac2 "AAA">>"/><br>
F: <$macrocall $name="mac" mac_param="""<<mac2 "AAA">>"""/><br>
</$set>
```

A: VVV
B: <<var>>
C: <<var>>
D: MMM: AAA
E: <$macrocall $name="mac" mac_param="MMM: AAA"/>
F: <$text text="MMM: AAA"/>

Reply all
Reply to author
Forward
0 new messages