[TW5] looping through an array in a macro

85 views
Skip to first unread message

Bob Flandard

unread,
Sep 13, 2015, 4:48:18 AM9/13/15
to TiddlyWiki
Hello,

Is it possible to define an array and pass it as an argument to a user defined macro and then loop through each element of the array within the macro?

Thanks, Bob

Evolena

unread,
Sep 13, 2015, 4:56:55 AM9/13/15
to tiddl...@googlegroups.com

Of course, something like that:

\define myMacro(filter)
<$list filter="""$filter$""">
{{!!title}}
</$list>
\end

<<myMacro "[[HelloThere]] [[Macros]] [[ListWidget]]">>

Or, if you need to define your array in another way, with the same macro definition:

<$set name="myArray" filter="[[HelloThere]] [[SetWidget]]">
<$macrocall $name="myMacro" filter=<<myArray>>/
>
</$set>


Mat

unread,
Sep 13, 2015, 5:35:20 AM9/13/15
to TiddlyWiki
@evolena
 
<$list filter="""$filter$""">

I don't think the triple quotes are necessary, i.e enough with single quotes, or? 

<:-)

Bob Flandard

unread,
Sep 13, 2015, 6:08:29 AM9/13/15
to TiddlyWiki
Hello Evolena,

Thank you for your code suggestion but it's a bit too abstract for my tiny brain. I was thinking of something of the form:

\define myMacro(arg1 arg2)
for i in arg1:
 make a string that does something useful and insert $arg1[i]$ and $arg2[i]$ values
\end

myArray1=[string1, string2, string3]
myArray2=[number1, number2, number3]

<<myMacro 'myArray1' 'myArray2'>>


I could call a macro multiple times with different arguments, but I was hoping to simplify it and do it in a single call passing arrays.

Thanks, Bob




Mark S.

unread,
Sep 13, 2015, 7:38:36 PM9/13/15
to TiddlyWiki
The built-in tools don't work that way. You would probably need to write a widget or a javascript macro if you really want to do something step-wise.

But it if you explain what exactly it is you want to accomplish, there are a lot of clever people in this forum who have thought up all sorts of ways to accomplish complex tasks with the existing toolset.

Mark
Reply all
Reply to author
Forward
0 new messages