I have a macro that does some calculations with tiddler widths etc and, as long as the widths are not changed, always gives the same output - say 350px
I also have a listwidget wherein the stuff uses the result from the above macro - in other words, it calls the macro for each interation in the listwidget.
The repeated calling+execution of the macro, to always get 350px, seems inefficient.
Can I call a static variable to get 350px instead of calling for it to be calculated every time?
I’m guessing $wikify or $set or our prettyboy $let but I’m not sure if any of them really holds a static string, of if its variable is recalculated every time it is invoked, and I don’t know how to test this.
I think \parameters is a semantic solution. But macro/procedure/$let/$vars should be fine.
I do not think there is a measurable performance effect using either of variable definition methods.
By the way, let’s see what advanced users think!
Of course there are state, temp and volatile tiddlers available for similar applications and you can create a function or variable based on such a tiddler or direct reference.
Such tiddlers can in effect only exist in memory
The thing is to set a field or tiddler needs a trigger so we need to consider if the change of the value has a trigger.
If I understand the tiddlywiki system changes to a tiddler will cascade through all its references
The thing is to set a field or tiddler needs a trigger
Right; there is no trigger. My construct is a dynamic stylesheet, no “buttons” or whatever for the user to click and I think storing the result physically should not be needed.
To spare more suggestions about physically storing the value, here’s the actual thingy: It calculates the width of the tiddler content, which (as far as I know) has to be calculated:
(I’m revising an old creation of mine so I am, at the moment, not quite sure where I get the magic numbers from but I guess it’s summed up tiddler gutters+margins.)
Right, but so are you saying that a variable inside the stylesheet, set via either of $wikify, $vars, $set, $let is necessarily always also recalculated (see OP)?
Which clues you in to the solution. You don’t want static, the value needs to be (re)calculated (but outside the loop, like we discussed recently but I can’t be arsed to go look up a link).
<<glob>> renders fine, even in a style block, but <<width-thing>> isn’t rendered at all. I tested the filter in $:/AdvancedSearch (pass). I tested the value of <<width-thing>>inside the $set (pass). Seems conditional assignment does not work globally, it’s just “blank”. I tested a really simple one, glob2 in the following…
I’ve never really liked to construct, tbh. Seems a bit screwy to me, (tramples over my understanding of “scope”). But the docs say it should work (and would be a nice/alternative solution (maybe) for Mat).
I am as usual fiddling with a plugin for the community. Hope to release it today or else this weekend, so I’ll show everything in it to give the full context for the OP. Thanks again for looking at it!