assigning macro output to a variable

57 views
Skip to first unread message

CarloGgi

unread,
Dec 15, 2021, 2:02:08 PM12/15/21
to TiddlyWiki
Hi everybody,
the struggle to get TW do what I want it to do goes on hopelessly.
I have a database of systems described by one data tiddler each, like this:

system_1
      tag: system
      feature 11: Y/N
      feature 12: Y/N
      feature 13: Y/N
      feature 14: Y/N

system_2
      tag: system
      feature 21: Y/N
      feature 22: Y/N
      feature 23: Y/N
      feature 24: Y/N

as you can easily guess, the tiddlers record what features system X supports or not.
Now I want to flexibly query my database for a certain feature, so I came up with this code:

\define check_feature(feature) [getindex[$feature$]trim[]match[Y]]

<$set name="has_feature" value=<$macrocall $name='check_feature' feature='IFTTT'/> >
  <ul>
      <$list filter="[tag[system]filter<has_feature>]" variable="sys">
          <li> <$link to=<<sys>>> <<sys>> </$link> </li>
      </$list>
  </ul>

</$set>

(in the example above I'm checking which systems are supported by IFTTT as you can imagine...). Fair enough, the above code DOESN'T work, because you cannot put a <$macrocall> widget as right-side element of the 'value' element of a <$set> widget. Ok, so how do I go? I know I could instead write:

<$set name="has_feature" value=<<check_feature IFTTT>> >

and that would work, but I need to use the <$macrocall> widget because the next step is to make the 'feature' parameter dynamically chosen via a <$select> instruction, so I would need to call the macro as below:

<$macrocall $name='check_feature' feature={{!!current_chosen_feature}}/>

where of course field 'current_chosen_feature' wouldbe set by the <$select> widget.


Thanks in advance for helping. More and more TW seems to me like a too much beautiful, too much independent woman: you love her but you cannot make her listen to you...


Charlie Veniot

unread,
Dec 15, 2021, 3:13:01 PM12/15/21
to TiddlyWiki
G'day,

You might be getting into some paralysis by analysis or analysis by paralysis (which is how I operate),
or maybe you have some programming experience that is interfering with the "TiddlyWiki Way" (I'm a systems analyst and software developer, and I keep falling into the trap of seeing macros as functions),
or I might be totally out in left field, which happens frequently.

Just to get a baseline for discussion, download the attached, drag it into tiddlywiki.com to import the tiddlers, and give the imported tiddlers a look.

Do the queries in the "Query systems" tiddler make sense?

QueryingSystemsDB_TW.json

Brian Theado

unread,
Dec 16, 2021, 8:06:14 PM12/16/21
to tiddl...@googlegroups.com
CarloGgi,

On Wed, Dec 15, 2021 at 2:02 PM CarloGgi <car.g...@gmail.com> wrote:
\define check_feature(feature) [getindex[$feature$]trim[]match[Y]]

<$set name="has_feature" value=<$macrocall $name='check_feature' feature='IFTTT'/> >
  <ul>
      <$list filter="[tag[system]filter<has_feature>]" variable="sys">
          <li> <$link to=<<sys>>> <<sys>> </$link> </li>
      </$list>
  </ul>

</$set>
[...] 
<$macrocall $name='check_feature' feature={{!!current_chosen_feature}}/>

where of course field 'current_chosen_feature' wouldbe set by the <$select> widget.

Filter operators can use transclusions for parameters. That should help with this case. Something like this (untested):
 
<$list filter="[tag[system]] :filter[getindex{!!current_chosen_feature}trim[]match[Y]]" variable="sys">

Flibbles

unread,
Dec 20, 2021, 11:02:54 AM12/20/21
to TiddlyWiki
I know I'm late, but variables may work better than arguments if you want to keep the filter separate.

\define check_feature() [getindex<feature>trim[]match[Y]]

<$let
    feature={{!!current_chosen_feature}}
    has_feature=<<check_feature>>

  <ul>
      <$list filter="[tag[system]filter<has_feature>]" variable="sys">
          <li> <$link to=<<sys>>> <<sys>> </$link> </li>
      </$list>
  </ul>
</$let>
Reply all
Reply to author
Forward
0 new messages