Proof of Concept: Dynamic Global Variables

246 views
Skip to first unread message

Felicia Crow

unread,
Sep 13, 2020, 10:50:14 AM9/13/20
to TiddlyWiki
Hi,

after Tony has asked about it in another thread and taking far longer than planned - trying to reinvent the wheel is maybe not the best solution - I finally finished a first proof of concept for dynamic global variables.

What this basically does is it adds a widget that works like set, just without the scope restrictions. So variables set with it can be used in the same tiddler further down or in another tiddler altogether.
I also added a custom filter operator to make it easier to access the variable values within a filter.

The attached wiki contains basic examples for how to use the widget/operator, while the json is there to make it easier to import it into your own wikis.

Usual Disclaimer: This is a very basic proof of concept not a finished plugin so while I am happy if people try it out and give feedback/develop it further I consider it very much use at your own risk.

Kind Regards,
Felicia
dgv.html
dgv.json

Saq Imtiaz

unread,
Sep 13, 2020, 11:56:32 AM9/13/20
to TiddlyWiki
Interesting implementation, thanks for sharing. 

It's a bit like an action-setfield widget that doesn't need a trigger. 

I've only had the most cursory look, but you could allow an optional widget parameter that determines the storage tiddler, allowing restricting scope where desired.
Perhaps also consider using a $:/temp.. or $:/state... prefixed tiddler for the storage.

Cheers,
Saq

Felicia Crow

unread,
Sep 13, 2020, 3:15:57 PM9/13/20
to TiddlyWiki
Saq,
yes somewhat, just for now without the ability to set where it saves. I drew the comparsion to set since what it is at the end of the day is the set widget just with a change to where it saves the value.

The thing is I at first wanted a user defined save location, but through tests I learned that the function I use to write the indexes to the tiddler needs the tiddler it writes to to actually to exist. So I decided to finish a first working proof of concept and expand this type of functionality in later revisions since I have to implement a fall back that creates a tiddler if it isn't there or at least gives the user a clear message that the set failed, because of the tiddler not existing.

As for the the prefixed tiddlers you are right this was more a result from me wanting everything in one place during development.
Although I would wish there was $:/data as this is neither necessarily temporary - I do wish to keep a saved beyond closing the wiki possibility should someone find a way to find it useful - or a state in the way it is apparently normally used within tiddlywiki, but from the next iteration onwards I will move it to $:/state.

Thanks for looking over it and giving feedback.

Kind Regards,
Felicia

PMario

unread,
Sep 13, 2020, 3:28:59 PM9/13/20
to TiddlyWiki
On Sunday, September 13, 2020 at 4:50:14 PM UTC+2, Felicia Crow wrote:

after Tony has asked about it in another thread and taking far longer than planned

Hi Felicia,

Interesting! ... Can you provide a link to the initial discussion, that triggered this functionality?

-mario

Mat

unread,
Sep 13, 2020, 3:32:33 PM9/13/20
to TiddlyWiki
@Felicia

Thank you for this! I can believe it will be useful ... but I'm wondering why I didn't need it thus far. Are there cases that usually can't be accomplished, or with much difficulty, that your creation solves better? (Maybe I should ask Tony) I also imagine it's one of those things that were at one time, early on, decided against for some secuity reasons - anybody knows?


<:-)

Felicia Crow

unread,
Sep 13, 2020, 5:23:50 PM9/13/20
to TiddlyWiki
Mario,
It was actually not the original discussion that triggered it, but me providing a javascript solution to the problem and Tony then asking if something like this was possible now that I had gotten some understanding of using javascript in tiddlywiki. Looking back at it now it is interesting to see how far this thing has changed from its macro beginnings.

Mat,
this answer is definitely on Tony. I personally also have yet to find an actual need for it, but this would be the first time not having a use for a tool to stop me from at least trying to build it, when it sounds interesting.
As for security reasons I am not sure. Maybe it could also fall under the more trouble than it's worth category, seeing how easy it is to overwrite a variable with something that then could break things further down the line, while not necessarily finding much use that can't be solved in another way.

Kind Regards,
Felicia

TW Tones

unread,
Sep 13, 2020, 9:47:24 PM9/13/20
to TiddlyWiki
Mat et al

Just to clarify where this came from first, then I will explain why.

First, Felicia, thanks so much for this, I was confident yu would work on this and happy to wait, in part because I think you say the gap yourself. I will review and reply in more detail soon.

For the last few years I have committed to tiddlywiki as a platform I intend to publish in, provide solutions and use as a business tool, as well as the joy of a collaborative community. As was the case earlier in my life when I aim to become expert in something, it takes time, because of the way I learn, very conceptually, concise and complete but via creative exploration, but once I know something well, it is usually very deeply. Apart from my working life in IT this has included, MS-DOS, Windows, Basic, Cobol, Evolution, Climate Change, Photography, WebSite Development, Sustainability and now tiddlywiki. 

Because I consider TiddlyWiki a platform and a future backbone to much of what I do, and being a frustrated app developer, my focus on tiddlywiki is pushing its limits, finding its flaws, identifying its gaps. With a deep understanding of procedural languages there is a class of things I would like to do (no doubt others) in tiddlywiki that it can't. Every month or so we the community tend to break another barrier expanding tiddlywikis possibilities down many paths. Off line I have the result of thousands of hours of development and exploration, documentation etc...  mostly which I currently share via the forum as needed.

Now perhaps this explains why I am sometimes a pain in the neck to some of my tiddlywiki colleagues, I am always looking to identify gaps and fill them. Thanks to many we continue to do so. Some very exciting stuff is about to come from work with Mario, as is often the case, but this time I has a role.

The following is from a programmers perspective
The specific Gap Felicia has worked to resolve is one I identified early, and I now have some workarounds, this "problem" means you can NOT count (or accumulate) a number of different things, using a number of widgets or accumulate over time without having a trigger, like a button to commit it to storage, in a tiddler or field. Each time you define a variable it in effect becomes a new variable in the current context. That is within tiddlywiki variables are fleeting definitions, although they must always be defined (eg: macro, set vars), so they they are always redefined. That is variables in tiddlywiki do not behave like variables in most programming languages, especially when you try and make them global, accessible outside one tiddler or loop etc.. and yet be able to be saved without a trigger. 
  • global variables are possible, but they are "static global variables" without a trigger to commit them.
  • If you are forced to commit them with an action you force the user to know what they are doing.
This kind of thing is strait forward in any computer language, including javascript but it has not being "surfaced" until now in tiddlywiki.

I am very excited about Felicia's work.

Feel free to question, further, even challenge my assumptions, it all about learning and developing tiddlywiki.

Regards Tony/TW Tones

TW Tones

unread,
Nov 24, 2020, 6:25:32 PM11/24/20
to TiddlyWiki
Felicia et all.

I am only now getting to see how to make use of this, it is constructed differently to how I imagined it, so it requires a learning curve.

would this be possible?

A test case would be if I had 2 list widgets 
set
<$list filter="[range[1, 5]]">
inc
</$list>

<$list filter="[range[11, 15]]">
inc
</$list>

total

An a global; variable could be set to zero before these list widgets, then for each iteration in both lists increment that variable so at the end the global value would be in this case 10

Try this in a single tiddler

<$setglobal name="inc" value={{{ [[inc]getglobal[]add[1]] }}}  />

{{{ [[inc]getglobal[]add[1]limit[1]] }}} 

{{{ [[inc]getglobal[]] }}}

Tones
Reply all
Reply to author
Forward
0 new messages