filter: duplicating values or reusing it for strings generation

70 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Sep 18, 2020, 1:27:41 PM9/18/20
to TiddlyWiki
I have a TW where some tiddlers are also tags. They tags themselves and a bunch of other tags.

For each of those tags, I want to tell how many tiddlers tag them and make a list of them which would look like that if I do it manually (the case as of now):

!!! [[foo tiddler]]
{{foo tiddler}}

!!! [[bar tidller]]
{{bar tiddler}}

(the link allow me to edit them, but I want to see their contents on my page.)

As for the number of tiddlers, I have done this macro:
\define counting()
<$set name="qty" filter="[all[current]tagging[]butfirst[]count[]]">
<$set name="label" filter="[all[current]tagging[]butfirst[]count[]compare:number:gt:[1]then[tests]else[test]]">
<<qty>> <<label>>
</$set></$set>
\end

which I used like this, simply:

<<counting>>

and I get something like "42 tests" or "1 test". (the tagging tiddlers are describing tests).

the problem in my macro "counting" is that I am duplicating code to get the tiddlers and count them. I have tried with auxilliary variable or macro, but I was unable to get it work.

Also, the work to get the tiddlers would also be of use for generating my list. As for this one, I would need a "map" filter and a "reduce" or "join" filter to achieve my goal. But these do not exist. And with the tools available, I can get my list of tiddlers, and use strings filter operator to make something ot of it. I've read that I would need special attention as I want to output tiddlywiki code to be interpreted by TW instead of basic texts, but for the time being, just outputing the tw code would be so sweet!

If the current tiddler in my filter generated list of tiddlers is "fubar", I can easily transform it in "!!! [[fubar]]" or "{{fubar}}" but I am unable to get "!!! [[fubar]]\n{{fubar}}" because I can't duplicate "fubar" or don't know how to. An other possibility would be a sprintf-like filter or macro.


TW Tones

unread,
Sep 18, 2020, 7:53:09 PM9/18/20
to TiddlyWiki
Hi,

the problem in my macro "counting" is that I am duplicating code to get the tiddlers and count them. I have tried with auxilliary variable or macro, but I was unable to get it work.  

  • In many ways this is not a problem in itself unless you have very large data
  • You could manipulate the second filter to also count and prefix the output with the number, however little is gained
  • Keeping it as it is is more clear and self documenting
Also, the work to get the tiddlers would also be of use for generating my list. As for this one, I would need a "map" filter and a "reduce" or "join" filter to achieve my goal. But these do not exist. 

Then we create them, but I am not sure that we can't do the equivalent already. I am not sufficiently well versed to build these, if you could define the terms as you envisage, perhaps I/others can build something. There is Join and split and more in filters already, but the tiddler as record makes this easy.

And with the tools available, I can get my list of tiddlers, and use strings filter operator to make something ot of it. I've read that I would need special attention as I want to output tiddlywiki code to be interpreted by TW instead of basic texts, but for the time being, just outputing the tw code would be so sweet! 
 
To generate code is quite easy,  but to see anything, tiddlywiki does a final render to html. Its understanding this that that will help you implement this. Many of us make use of templates as does the system to export json and static tiddlers. A template contains the login of the output and that result is evaluated (eg wikified) to generate the result.

When it comes to templates some advice I got which, I have not explored in detail yet,  is using the macro definitions to contain the template definitions, using $(varname)$ substitutions to incorporate dynamic content.

You mention "map" filter and a "reduce" or "join" 
I am investigating using tiddlywiki as a tool for manipulating LittleData rather than bigdata. Basically to extract optimised decision trees etc... Then "little bit bigger data" can be logging of activity in tiddlywiki itself, so we can build smart analytics that observes the authors use of tiddlywiki, with a view to discovering things not evident on the surface.

Perhaps you could expand on this?  
If the current tiddler in my filter generated list of tiddlers is "fubar", I can easily transform it in "!!! [[fubar]]" or "{{fubar}}" but I am unable to get "!!! [[fubar]]\n{{fubar}}" because I can't duplicate "fubar" or don't know how to. An other possibility would be a sprintf-like filter or macro.  
  • Here your provide a pseudo code for what you want, perhaps ask for it in plain English?
  • I am sure the below is enough to answer, although perhaps technically it does?
Here is my Guess at a solution

<$list filter="[[fubar]]">

!!<$link/>
<$transclude/>
</$list>

I use list simply to set the current tiddler and use the defaults for the link and transclude widgets.

Regards
Tones

Jean-Pierre Rivière

unread,
Sep 20, 2020, 10:46:18 AM9/20/20
to TiddlyWiki


Hi Tones.

Thank you for your answers. Theses mostly solved my problem.

* for the duplication of filter code
OK with speed. It is simple to understand if code is duplicated but it is more awkward to maintain and who knows if the identity of most code is really intended or just a bug? I mean, from what you tell me, I don't care about running that code twice, but I would like to write it only once.

could I do something like:

<$set name="selectRelatedTests" text="all[current]tagging[]butfirst[]">
<$count filter="<<selectRelatedTests>>"/> tests:
<$list filter="<<selectRelatedTests>>">
!!! <$link>
<$transclude>
</$list>
</$set>

This code does not work. But wouldn't it be more clear and maintenable than the one below:

<$count filter="<<all[current]tagging[]butfirst[]>>"/> tests:
<$list filter="<<all[current]tagging[]butfirst[]>>">
!!! <$link>
<$transclude>
</$list>

Or something along that way of thinking (with my filter being written only once even if it means more code otherwise). Also, you can see that your proposed solution with $list was a perfect solution for me. I keep it as is.

BTW I think I discovered a bug. Actually, the tiddler to be transcluded begins with a definition like

; tiddlywiki
: really cool stuff

With a direct inclusion like {{myTiddler}} that's OK and the definition is printed correctly on screen. With the inclusion through $link and $transclude, the definition is not interpreted as wiki code but shown as raw wiki code, whereas bullets are correctly rendered, for instance. Shouldn't I create a ticket for this?

Jean-Pierre Rivière

unread,
Sep 20, 2020, 11:51:41 AM9/20/20
to TiddlyWiki
OK, I saw what was wrong with me not having the definition wiki syntax interpreted. That was because I did not specify the mode in the transclude widget, which was set to inline by the system whereas I needed to have it into block mode. So I now do

<transclude mode="block"/>

and all is fine.

So I now have written one of my collection of test page with something like:

! {{!!criterion}}

<$set name="things"
filter="[all[current]tagging[]butfirst[]count[]compare:number:gt[1]then[tests]else[test]]">

!! <$count filter="[all[current]tagging[]butfirst[]]"/> <<things>> pour le {{!!title}}

</$set>
<$list filter="[all[current]tagging[]butfirst[]]">

!!! <$link/>
<$transclude mode="block"/>
</$list>

!! Particular cases
....bla-bla-bla...

I think I now need to figure out to have the part from the beginning up to </$list> as a kind of template for these type of tiddlers. But this is only a partial template. I'll come back to you with my solution (it may help someone) or with an other et of questions. Thank you for your patience.

Reply all
Reply to author
Forward
0 new messages