Please, help to write filter a1 a2 a3 ...+b1 b2 b3 ...= a1 b1 +a2 b2 + a3 b3 +...

116 views
Skip to first unread message

Siniy-Kit

unread,
Dec 6, 2020, 5:53:52 AM12/6/20
to tiddl...@googlegroups.com
Hi,  i have two fields in my tiddler
select-color: red green blue red
price-select-color: 100 100 30 101

I want to get text, using $filter
red - 100
green - 100
blue - 30
red - 101

how to do it in the simplest way? 

Mohammad

unread,
Dec 6, 2020, 6:20:22 AM12/6/20
to TiddlyWiki
Siniy-kit, 

Are you allowed to use a data dictionary and hard code values like this
red: 100
green: 200
blue: 30
If so just search in a data dictionary.

On Sunday, December 6, 2020 at 2:23:52 PM UTC+3:30 Siniy-Kit wrote:
Hi,  i have two fields in my tiddler
select-color: red green blue
price-select-color: 100 200 30

I want to get text, using $filter
red - 100
green - 200
blue - 30

Siniy-Kit

unread,
Dec 6, 2020, 8:39:48 AM12/6/20
to TiddlyWiki
Hi,  Mohammad. Unfortunately I cant use    dictionary  variant.
my idea was to combine lists   select-color +  price-select-color order[reverse]  and then cut one by one first - last
but hope, somebody knows another way....

воскресенье, 6 декабря 2020 г. в 14:20:22 UTC+3, Mohammad:

Mark S.

unread,
Dec 6, 2020, 9:50:18 AM12/6/20
to TiddlyWiki
Something like this, maybe:

<$list filter="[range[1,4]]" variable="index">
<$list filter="[enlist:raw{!!select-color}nth<index>]" variable="color">
<$list filter="[enlist:raw{!!price-select-color}nth<index>]" variable="price">
<<color>> - <<price>>
</$list></$list></$list>

Mark S.

unread,
Dec 6, 2020, 10:00:45 AM12/6/20
to TiddlyWiki
Version where you don't have to specify range by hand

\define color-price(end)
<$list filter="[range[1,$end$]]" variable="index">
<$list filter="[enlist:raw{!!select-color}nth<index>]" variable="color">
<$list filter="[enlist:raw{!!price-select-color}nth<index>]" variable="price">
<<color>> - <<price>>
</$list></$list></$list>
\end

<$list filter="[enlist:raw{!!select-color}count[]]" variable="end">
<$macrocall $name="color-price" end=<<end>>/>
</$list>


Siniy-Kit

unread,
Dec 6, 2020, 10:23:31 AM12/6/20
to TiddlyWiki
Thank you, Mark! I didn't know about range!  

<$set name="end" value={{{[enlist:raw{!!select-color}count[]]}}}> 
<$list filter="[range<end>]" variable="index">
<$list filter="[enlist:raw{!!select-color}nth<index>]" variable="color">
<$list filter="[enlist:raw{!!price-select-color}nth<index>]" variable="price">
<<color>> - <<price>>
</$list></$list></$list>
</$set>

воскресенье, 6 декабря 2020 г. в 18:00:45 UTC+3, Mark S.:

Eric Shulman

unread,
Dec 6, 2020, 8:00:43 PM12/6/20
to TiddlyWiki
Here's another approach that uses recursion:

\define merge(list1,list2)
<$list filter="[[$list1$]!match[]then[$list2$]!match[]]">
<$text text={{{ [enlist:raw[$list1$]first[]] }}}/> - <$text text={{{ [enlist:raw[$list2$]first[]] }}}/><br>
<$macrocall $name="merge" list1={{{ [enlist:raw[$list1$]rest[]join[ ]] }}} list2={{{ [enlist:raw[$list2$]rest[]join[ ]] }}} />
</$list>
\end

<$macrocall $name="merge" list1={{!!select-color}} list2={{!!price-select-color}} />

-e
Reply all
Reply to author
Forward
0 new messages