Macros parameters inside filters

Having read the doc about that topic and the use of the qualify macro as an example, I tried some variations of code to get used of what is OK and what is wrong. See the code below.

\define myMacro(stateTid:"")
<$vars stateTid={{{ [<__stateTid__>!is[blank]then<qualify "$:/temp/slider/$(currentTiddler)$/$stateTid$">else<qualify "$:/temp/slider/$(currentTiddler)$">]}}} >

This is <$text text=<<stateTid>> />

</$vars>
\end

\function .mySubfilter(acrr, target) [[qualify]addsuffix[ ]addsuffix<curr>addsuffix[/]addsuffix<target>dump[const. subfilter]]

\function .myFunction(stateTid)
[<__stateTid__>!is[blank]then<qualify "$:/temp/slider/$(currentTiddler)$/$stateTid$">else<qualify "$:/temp/slider/$(currentTiddler)$">]
\end

\function .myInner(curr, target) [<qualify>[$:/temp/slider/$(curr)$/$(target)$]]
\function .myOtherInner(curr, target) [[qualify]addsuffix[ ]addsuffix<curr>addsuffix[/]addsuffix<target>]

\function .myOtherFunction(hereTid, stateTid)
[<stateTid>dump[state]!is[blank]] :map[all[]dump[good curr].myInner<hereTid>,<stateTid>dump[res]] :else[.myOtherInner<hereTid>dump[alt]] +[dump[final]]
\end

\function .mySubfedFunction(hereTid, stateTid)
  [<stateTid>dump[state within]'<hereTid>'!is[blank]]
  :map[all[]dump[good curr].myInner<hereTid>,<stateTid>dump[res]]
	:else[.myOtherInner<hereTid>dump[alt]]
	:map[[<qualify "$1$">]dump[motif]substitute<currenTiddler>dump[exp with],<currentTiddler>,[AS]subfilter<currentTiddler>dump[final]]
\end

* <<myMacro clubs>>
* That is {{{ [.myFunction[clubs]] }}}
* And then {{{ [.myOtherFunction<currentTiddler>,[clubs]] }}}
* And last {{{ [.mySubfedFunction<currentTiddler>,[clubs]] }}}

note that dump is a filetr operator to output input on the javascript console with all arguments concatened with space before the array of thi input. Quite handy. I let thhem be here to show you what is happening.

Now, the output:

=============

  • This is $:/temp/slider/macros parameters inside filters/clubs-2141172816
  • That is $:/temp/slider/$(currentTiddler)$-2141172816
  • And then $:/temp/slider/$(curr)$/$(target)$
  • And last qualify
    =============

in the javascript console we got:


23:52:31,675 paumé #1 Array [ ‘<qualify “clubs”>’ ]
23:52:31,681 state #1 Array [ “clubs” ]
23:52:31,681 good curr #1 Array [ “clubs” ]
23:52:31,682 res #1 Array [ “$:/temp/slider/$(curr)$/$(target)$” ]
23:52:31,682 final #1 Array [ “$:/temp/slider/$(curr)$/$(target)$” ]
23:52:31,682 state within #1 Array [ “clubs” ]
23:52:31,682 alt #1 Array [ “qualify macros parameters inside filters/” ]
23:52:31,683 motif #1 Array [ ‘<qualify “$1$”>’ ]
23:52:31,683 exp with qualify macros parameters inside filters/ AS #1 Array [ ‘<qualify “”>’ ]
23:52:31,683 final #5 Array(5) [ “qualify”, “macros”, “parameters”, “inside”, “filters/”

(things like #1 indicate that the input on the right has only 1 title)

Big Question: why in “mySubfedFunction” the “substitute” filter op does not succeed in outputting <qualify "macros parameters inside filters"> ? My code seems so similar to the official example but is not working yet.

@jypre happy to help here, I am confident I can help, but the code and use of dump demands a lot of reverse engineering. Could you give a descriptive example of what you intend the result to be for a particular function, and I will write a fresh answer?

  • Where does the dump operator come from?
  • Remember any value already available to a function need not be added to the parameters. I try and write all my functions, procedure and macros to operate on currentTiddler, so need not give it as a parameter.
  • Also remember that the qualify returns a serial number that is formed from the current location (behind the scenes) so currentTiddler need no be used in the qualify prefix. Typically the prefix in qualify represents a group of state tiddlers, with the number uniquifying it. If however, you want the state tiddler to include the current tiddler in the state title, you can possibly abandon the use of the qualify macro as it will already be unique.

Post Script:

Whilst looking at this and related code snipits I thought I would share this custom widget, place in a tiddler tagged $:/tags/Global

\widget $show.code(code tooltip:"Inline code and result, click to copy" label result-label)
<$button tag=span tooltip=<<tooltip>> message="tm-copy-to-clipboard" param=<<code>> >
<<label>><span  style="background-color: #f2f2f2">"""<$text text=<<code>>/>"""</span>
</$button>&nbsp;<<result-label>>&nbsp;<span  style="border: 1px solid grey; border-style: dotted;"><<code>></span>
\end $show. Code

Then this;

Can be rewritten;

# <$show.code code="<<myMacro clubs>>"/>
# <$show.code code="{{{ [.myFunction[clubs]] }}}"/>
# <$show.code code="{{{ [.myOtherFunction<currentTiddler>,[clubs]] }}}"/>
# <$show.code code="{{{ [.mySubfedFunction<currentTiddler>,[clubs]] }}}"/>

Which shows;

  • Click to copy the code component to the clipboard
  • There are more parameters look at in the widget.

If you can think of a better name than $show.code let me know.

Coincidentally, I was struggling with substitute[] earlier today. Ended up going in another direction. But I’ll be watching this thread…

I would think this may be explored elsewhere as its somewhat off topic.

If you do I will share some recent experiments and conclusions;

  • Use functions and attribute backticks for most cases of substitution
    • use join if needed
  • Define and its substitutions still work and can be defined in and mixed with the new methods
  • The substitute operator is most powerful if it uses a template
\procedure line-template() Something in the $(time)$ at $2$ about $1$ 
\function templated. Line() [<line-template>substitute<subject>,<location>]

@TW_Tones

Uh, on topic, methinks. I had the SAME big question (but moved on).

I cant do more until I got the dump operator or a simple example is given.

Use this Introducing the debug-log[] filter

Do we know this is equivalent? dump vs debug-log?

  • but I have asked this

At a glance, yes. From experience? I’ve only used @Yaisog’s debug-log[].

(Wish it was shorter to type – I may fix that with a \function at some point).

Ha! it has a pseudonym: XXX[].

@TW_Tones Here it is.

dump.js.json (923 Bytes)