Scope of Macro Parameters

80 views
Skip to first unread message

Mohammad

unread,
Aug 9, 2019, 4:29:29 AM8/9/19
to TiddlyWiki
In https://tiddlywiki.com/
  • create a new tiddler
  • and copy paste the below script
  • save and see the output

Code
\define One(p1, p2)
;Inside One
:This is p1 in One: <$text text=<<__p1__>> />
:This is p2 in One: <$text text=<<__p2__>> />

!!Call Two without passing p1, p2

<<Two p3:300>>
\end

\define Two(p3)
;Inside Two
:This is p1 in Two: <$text text=<<__p1__>> />
:This is p2 in Two: <$text text=<<__p2__>> />
\end

<<One p1:100 p2:200>>


Output


Inside One
This is p1 in One: 100
This is p2 in One: 200

Call Two without passing p1, p2

Inside Two
This is p1 in Two: 100
This is p2 in Two: 200


That means scope of macro parameters span to all macro called from the main macro!

Is this correct? Is it practice to acces macro parameters in this way from other calling macros?

--Mohammad

Mohammad

unread,
Aug 9, 2019, 4:32:03 AM8/9/19
to TiddlyWiki
Note this

 
$p1$

does not work!

Jeremy Ruston

unread,
Aug 9, 2019, 4:46:47 AM8/9/19
to tiddl...@googlegroups.com
Hi Mohammad

Your conclusions are correct: macro parameters referenced as variables are inherited like any other variables.

To show what happens behind the scenes, a macro like this:

\define mymacro(a,b)
<$text text=<<__a__>>/>: <$text text=<<__b__>>/>.
\end

Would be equivalent to the following version that explicitly assigns to the variables:

\define mymacro(a,b)
<$set name="__a__" value="""$a$""">
<$set name="__b__" value="""$b$""">
<$text text=<<__a__>>/>: <$text text=<<__b__>>/>.
</$set>
</$set>
\end

Best wishes

Jeremy


--
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 tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/dd722b10-dd34-477c-ab28-a7af336ac9f7%40googlegroups.com.

Mohammad

unread,
Aug 9, 2019, 4:58:05 AM8/9/19
to TiddlyWiki
Hi Jeremy,

Thank you for clarification.

Cheers
Mohammad


On Friday, August 9, 2019 at 1:16:47 PM UTC+4:30, Jeremy Ruston wrote:
Hi Mohammad

Your conclusions are correct: macro parameters referenced as variables are inherited like any other variables.

To show what happens behind the scenes, a macro like this:

\define mymacro(a,b)
<$text text=<<__a__>>/>: <$text text=<<__b__>>/>.
\end

Would be equivalent to the following version that explicitly assigns to the variables:

\define mymacro(a,b)
<$set name="__a__" value="""$a$""">
<$set name="__b__" value="""$b$""">
<$text text=<<__a__>>/>: <$text text=<<__b__>>/>.
</$set>
</$set>
\end

Best wishes

Jeremy

To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

Mohammad

unread,
Aug 9, 2019, 4:58:19 AM8/9/19
to tiddl...@googlegroups.com
Added to TW-Scripts.

TonyM

unread,
Aug 9, 2019, 8:45:27 AM8/9/19
to TiddlyWiki
How does $(varname)$ operate the same way as `<<__varnam__>>` but is just replaceable text?

If so is this a way to "evaluate" a macro result into a string?

`\define stringval() $(varname)$

<$wikify name=varname text="{{!!field}} and <<othervar>>" >

<<stringval>>`

If so perhaps it would be nice if we could use $(varname)$ directly in wiki text? Rather than only inside a macro definition.

I assume $(varname)$ continues into subsequent macro calls?

regards
Tony

Reply all
Reply to author
Forward
0 new messages