TW Fundamentals: Test Your Understanding: Transclusion and "Scoping Boundaries" (?)

Kind of like a “flash cards” game …

Experienced TW users will instinctively know what’s going on here. Say nothing !

For anyone with no idea what is going on, ask.

For anybody not immediately sure but you figure it out: test your understanding by answering any questions. Otherwise: Say nothing!

If you provide enlightenment on what’s going on, please add reference links to relevant documentation in TiddlyWiki.com. If there isn’t a clear reference in TiddlyWiki.com, then documentation folk know what to do.

Tiddler B

It is referencing something (whatever it might be: variable, macro, whatever) “rightNow”.

But “rightNow” is undefined, so there is no “code substitution” of the reference. The reference is substituted with nothingness.

Knowing that, do you understand why the transcluded Tiddler B knows, in one context, what “rightNow” is, but then does not know, in the other context:

4 Likes

@Charlie_Veniot What fun! Thanks for the great puzzle idea. I hope you have time to make more of these.

Not quick witted enough to understand what I read on tw dot com in the tiddler “LetWidget”, ie.: “The content of the $let widget is the scope for the value assigned to the variable.”, your example makes clear to me that the variable name “rightNow” is only evaluated for text which is between the opening “<$let” and the closing “</$let>”. Tiddler B has no such widget so the “rightNow” is not evaluated to anything but is repeated as is. When Tiddler B is transcluded its text appears in Tiddler A and is then either evaluated by the now macro to appear as the current time and date when the transclusion code is within the boundaries of the letWidget, or not evaluated when it is outside of those boundaries.

In your puzzle I also learned about the “now” macro itself.

While congratulating myself on becoming slightly more informed about this TW which I’ve been using for years, I realize that I haven’t a clue about what the now macro is useful for since its value updates whenever you save a tiddler where it’s been used.

And I can imagine no practical example for the use of the letWidget. If the substitution you define within it is only applied within itself, it must be used with some other functionality than just text substituion. If that were so, you would just write what you meant to write in the first place. In the present case that would be writing <<now>> instead of “rightNow” within the whole letWidget code. I’m asking myself when and for what is this useful?

Could you think up a puzzle which makes that clear?

My recent answer shows <$let ... > being used to define a variable which is used to define other variables to break down complex problems. And it demonstrates a variable defined once being used more than once.

<$let ...> and its older cousing <$set ... > are pretty central to doing anything more complex in TW, I think.

To me, who is not busy? There are never enough hours in a day or days in a lifetime for anybody. So anybody taking a minute to write something nice like that, that’s a big deal. Thanks!

That is worthy of a distinct thread of discussion. After the workday, I’ll do a wee post about $set, $vars, and $let to challenge the way to understand them.

That is really nicely written/explained. Very good stuff. Bravo!

Now, off for my lunchtime stretchin’ o’ da legs, then a proper fill o’ da gullet, then back to the bread’n butter grind.

Here’s my crack at showing you let vs vars:

TW Fundamentals: Test Your Understanding: set vs vars vs let

1 Like

Check this out for a use case.

Thank you. Your example shows me that the now macro is an ingredient in some longer formulation, a big step forward.

I’m guessing that it is in use whenever you save a tiddler because there’s a light grey line beneath any tiddler’s title which shows the date and time at which it was most recently saved. Since everything in TW is a tiddler, to further my understanding, I would like to inspect the tiddler which causes this updating to time last saved to happen. Could someone tell me its name? Searching for <<now>> doesn’t list all the places where the macro is used.

When you add a new tiddler, it has a “created” date/time stamp. That would be from “now”.

Same thing for a tiddler’s modified date/time stamp.

For we TW users, now is pretty useful to put date/time values in the titles of journal tiddlers.

Otherwise, I haven’t needed “now”. I’d bet there are some interesting use cases for “now” that I would never think of. If we are lucky, maybe somebody can chime in with an interesting use case.

That’s a great question !

Now is made available to those that wish to obtain a date time stamp of various formats, the fomat:date[] operator can format tiddlywiki date time stamps and the view widget can be used to display it. These tools are made available to the users/designer. Creating and modifying tiddlers do not need now directly to manipulate date. Also note the official format for modified and created is [UTC]YYYY0MM0DD0hh0mm0ss0XXX such dates are stored in UTC and converted to the Local time to be displayed.

  • If you use {{!!created}} or {{!!modified}} you will see they are displayed with a format, that does not occur with other custom date fields.
  • Of course it depends on how you create or modify a tiddler as to the method used for setting created and modified date, this is built in to assist in the management of tiddlers, and you can actually use timestamp=no on some actions or turn it off in More > Tools
  • There are functions defined in the core that handle this, for example the action create tiddler widget uses this.wiki.getCreationFields and this.wiki.getModificationFields but ultimately date handling uses javascript to retrieve and format, But some Button and other TiddlyWiki scripts do make use of the now macro.

I see. Thanks for your good explanation. Now is built with something else deeper down. I tried to find that ‘something’ but using the developer console in a browser to search for “now” was inconclusive at best. When I tried opening one of my projects in a text editor, I found myself looking at one very long minified block of text. Searching there got me “$:/core/modules/macros/now.js … snip … function(format) {\n\treturn $tw.utils.formatDateString(new Date(),format || \“0hh:0mm, DDth MMM YYYY\”);”. I’m at best an advanced beginner with javascript but I enjoy reading it. Is there a way to see a non-minified version of a TW project file?

1 Like

Oh good. I don’t use the advanced search as one should. Will do so in the future. Thanks!

That’s a great way to get into the nitty-gritty details of things in TiddlyWiki.

For example, anything in TiddlyWiki that pops up some tooltip info upon mouse-hover, enter the text from that tooltip into the advanced search (System tab and/or Shadows tab) to explore.