proposal: private macro and variables

81 views
Skip to first unread message

Mohammad

unread,
Aug 30, 2019, 12:47:03 AM8/30/19
to TiddlyWiki
Description
It is quite common when developing a macro to do a specific task, it needs some auxiliary macros. For example I wrote a macro mySearch to do search in tiddlers text field which itself call another macro to show the result showResult in some specific format. Users only needs to call mySearch and not showResult.

These global macros (tagged with $:/tags/Macro) are anywhere available and  make the whole namespace messy.

Proposal
Like other programming language we can have sub macro or private members. For example TW core can prevent access to all macros in a tiddler tagged with $:/tags/Macro if their name meet some certian criteria for example: __NANE__  or __::NAME

Benefits
A tiddler tagged with $:/tags/Macro with many macro variables in it acts like a small namespace. Only certain macro can be called (are global) and other follow the above rule only accessible from inside that tiddler. Tiddlywiki will remain tidy, Global vars will not overwrite each other, ...


--Mohammad 
 
 

TonyM

unread,
Aug 30, 2019, 3:53:20 AM8/30/19
to TiddlyWiki
Mohammad,

I believe there are sufficient workarounds that are less complex to manage than you are proposing.

You could have macros in a tiddler and simply transclude them at the top of the tiddler or in a conditional transclude by the ViewTemplate. If the same macros are global and defined elsewhere they will be overwritten with your transcluded macros. For example you could use a tiddler-type field and include a specific macro set only for particular tiddler-types.

You could tag your macros and only include those with a particular tag.

The dumpvariables Macro is helpful with this kind of work and the new variables Operator can allow you to test if a variable exists and if not do something including transclude a tiddler containing "local macros".

If you wanted you could have in each tiddler a transclude-macros-list field that if present will transclude the named tiddlers containing the local macros (may need some backend work).

Regards
Tony





Mohammad

unread,
Aug 30, 2019, 4:34:36 AM8/30/19
to TiddlyWiki
Hi Tony,
 Yes there are workarounds.

For example in Python you import a module when you need it and by default they are not in access.
In TW we can use import variable pragma whenever we needs the macro and we can remove $:/tags/Macro

But all of these do not let the clean, less error prone route I proposed. I am not sure may be there is another solution in TW.

--Mohammad

@TiddlyTweeter

unread,
Aug 30, 2019, 4:55:24 AM8/30/19
to TiddlyWiki
Mohammad

I agree in the sense that the current approach is largely "flat", not "hierarchical". Its a "bucket" of all sorts.

BUT, to be honest, I never had problems with it. 

How much of an issue is this from the point-of-view of an end user?

Just thoughts
Josiah 

Jeremy Ruston

unread,
Aug 30, 2019, 5:13:41 AM8/30/19
to tiddl...@googlegroups.com
Hi Mohammad

You can use the existing import pragma to bring in macro definitions from other tiddlers without cluttering the global name space. For example, you might have a global macro defined in a tiddler tagged $:/tags/Macro, and then put your local macros into tiddlers just tagged $:/tags/MyPublisher/MyPlugin/LocalMacros. Then, at the top of your global macro you’d bring in those local macros with:

\import [all[shadows+tiddlers]tag[$:/tags/MyPublisher/MyPlugin/LocalMacros]!has[draft.of]]

\define myPublicMacro()


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/7dd82716-23d8-4be5-abd6-2028bab54d8f%40googlegroups.com.

Mohammad

unread,
Aug 30, 2019, 7:48:11 AM8/30/19
to tiddl...@googlegroups.com
Thanks Jeremy,
 
By the way I created a macro in a tiddler called "global macro" in tiddlywiki.com as below

\import [all[shadows+tiddlers]tag[$:/tags/localMacro]!has[draft.of]]


\define test() This is a test


The $:/tags/localMacro is used to tag my local macro and have few tiddlers tagged with $:/tags/localMacro

Then in another tiddler I wrote

<<test>>


Nothing is shown! Then I removed the first line and blank lines from "global macro" it works!

What is the problem?

--Mohammad

Mohammad

unread,
Aug 30, 2019, 7:51:33 AM8/30/19
to TiddlyWiki
Jeremy,

Seems has an issue

\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]

The last part has not balanced [].

--Mohammad

Mohammad

unread,
Aug 30, 2019, 8:02:55 AM8/30/19
to TiddlyWiki
Hi Josiah,
 For a programmer local macro give more flexibility without worrying about overwriting or precedence of macros.
Sometime final user should not see or have access the internal macros which cause confusion, wrongly using them and overwriting other vars.
It is always good to specify and restrict the scope of variable.

--Mohammad
Reply all
Reply to author
Forward
0 new messages