Tip: Stuck with wrong variable for two days

99 views
Skip to first unread message

Mohammad

unread,
Apr 1, 2020, 6:25:52 PM4/1/20
to tiddl...@googlegroups.com
Assume you have a macro called path in tiddler aa like (have NO tag)

\define path() $:/folder1/subfolder11


Then in another tiddler called bb and tagged with $:/tags/Macro you have the below macro

\define mymac(file)
\import aa
<$vars fullpath="$(path)$/$file$">
some code go here
!
<<fullpath>> is wrong!
</$vars>
\end


Note to the import pragma! Call mymac like below in your tiddler of choice

<<mymac readme>>

You see wrong result for fullpath as $(mName)$ does not work anymore!

I did not know when you import a macro, then you cannot use it like $(mName)$

This is the benefit of well documented Tiddlywiki !!!!

What do you think?


--Mohammad

Eric Shulman

unread,
Apr 1, 2020, 7:57:39 PM4/1/20
to TiddlyWiki
I did not now when you import a macro, then you cannot use it like $(path)$

A macro only does two kinds of processing:
* replace occurrences of $foo$ with the value passed in as a parameter
* replace occurrences of $(foo)$ with the value of a variable defined *outside* the macro

It then returns the contents of the macro, with the replacements, which can then be further parsed in the calling context.
Thus, in your example, using the "\import aa" pragma inside your macro doesn't work as you want because $(path)$ is not defined *outside* the macro definition.

The following, however, DOES work...

in bb, write:
\define mymac_inner(file)

<$vars fullpath="$(path)$/$file$">
some code go here
!
<<fullpath>> is wrong!
</$vars>
\end

\define mymac(file)
\import aa
<<mymac_inner $file$>>
\end

Using the above, you can then call <<mymac readme>> from another tiddler, and get the results you expect.

enjoy,
-e







Mohammad

unread,
Apr 2, 2020, 2:07:51 AM4/2/20
to TiddlyWiki
Many thanks Eric,
 So the nested import pragma causes all imported macros act as nested macro means they are inside parent macro and we cannot use $(mName)$ any more!
 
 One more repetitive question: does $(mName)$ mean the value of mName is parsed and <<mMacro>> mean a pointer passed (without parsing)?

--Mohammad

Mohammad

unread,
Apr 2, 2020, 2:08:08 AM4/2/20
to TiddlyWiki
Added to TW-Scripts


On Thursday, April 2, 2020 at 4:27:39 AM UTC+4:30, Eric Shulman wrote:

TonyM

unread,
Apr 2, 2020, 7:20:48 AM4/2/20
to TiddlyWiki
Mohammad

I think what Eric's example says is importing a macro defines it in the tiddler its imported to but you need to call it '<<macro>>` to get it to access parameters or variables like $(var)$ but when you import it you can import one that calls another.

Otherwise there something subtle in the words you use to summarise Eric's work that sounds slightly incorrect.

Regards
Tony

Mohammad

unread,
Apr 2, 2020, 9:15:24 AM4/2/20
to TiddlyWiki
Tony,
 I need to call macro like $(xx)$ i.e. transcluded variable!
But when I use \import pragma inside a macro, it like I define one macro inside another macro not OUTSIDE it and so I cannot use $(xx)$

--Mohammad

TonyM

unread,
Apr 2, 2020, 5:46:50 PM4/2/20
to TiddlyWiki
Mohammad,

I will try and reproduce this today and look into it because I am also following the lead to use macro definitions as templates for text fields. This would allow creating complex wiki text containing values passed to it via variables.

\define tt()
Welcome $(username)$<br>

<h3>Your Outstanding tasks are</h3>
...
\end

Your observation could affect this code pattern.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages