Mailing List Archive

Reduce & inlist
Hi all,

i found in ML archives recipe how to remove duplicates from list,
i tried it in that form in file used -be input:

APPEND_ITEM = ${if def:value {$value,$item}{$item}}
INLIST = inlist{$item}{<,$value}

${reduce{<, item1, item2, item1}\
{}\
{${if INLIST{$value}{APPEND_ITEM}}}}

It works in 4.94, but doesn't work in 4.96 nor 4.97 (all stock debian
packages). In the 4.96 & 97 it returns only "item1". From debug
output and docs i understand, that when item is in list, the $value
inside inlist contains matched item not that one from reduce, thus
that matched item replaces result in reduces..

I found some discussion about that in this thread
https://lists.exim.org/lurker/message/20220922.124818.33ca8de7.es.html
but i lost in it...

Then i want to replace inlist by forany, but here is collision with $item
values, thus i didn't try it. Finally i replaced inlist with match condition,
which works, but i would to awoid regex if possible .

Please, is here better way to remove duplicates than use regex
in condition?

regards

--
Slavko
https://www.slavino.sk/

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Reduce & inlist [ In reply to ]
On Wed, Feb 28, 2024 at 05:30:35PM +0000, Slavko via Exim-users wrote:

> Please, is here better way to remove duplicates than use regex
> in condition?

I have no real solution, but as tricky as it seems to be, I think a
new built-in expansion operator to uniquify a list would be a good
thing.

If I were in the OP shoes, I'd try to work around by using a db
lookup instead of a list, maybe with the help of the "seen" feature.

--
Ian

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Reduce & inlist [ In reply to ]
On 2024-02-28, Slavko via Exim-users <exim-users@lists.exim.org> wrote:
> Hi all,
>
> i found in ML archives recipe how to remove duplicates from list,
> i tried it in that form in file used -be input:
>
> APPEND_ITEM = ${if def:value {$value,$item}{$item}}
> INLIST = inlist{$item}{<,$value}
>
> ${reduce{<, item1, item2, item1}\
> {}\
> {${if INLIST{$value}{APPEND_ITEM}}}}
>
> It works in 4.94, but doesn't work in 4.96 nor 4.97 (all stock debian
> packages). In the 4.96 & 97 it returns only "item1". From debug
> output and docs i understand, that when item is in list, the $value
> inside inlist contains matched item not that one from reduce, thus
> that matched item replaces result in reduces..
>
> I found some discussion about that in this thread
> https://lists.exim.org/lurker/message/20220922.124818.33ca8de7.es.html
> but i lost in it...
>
> Then i want to replace inlist by forany, but here is collision with $item
> values, thus i didn't try it. Finally i replaced inlist with match condition,
> which works, but i would to awoid regex if possible .
>
> Please, is here better way to remove duplicates than use regex
> in condition?

I see what you mean, "${if inlist" doesn't seem to work inside "${reduce"


I have in the past written complex loops using "${map" "${foreach" or "${filter"
and "${acl" but I'm not going to say that this is "better".

Embedded Perl is possibly a better approach, but it's been a decade
since I used that for anything.

--
Jasen.
???????? ????? ???????

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Reduce & inlist [ In reply to ]
D?a 28. februára 2024 18:07:47 UTC používate? Ian Z via Exim-users <exim-users@lists.exim.org> napísal:

>I have no real solution, but as tricky as it seems to be, I think a
>new built-in expansion operator to uniquify a list would be a good
>thing.

I found solution (workaround) -- move $value outside of inlist:

INLIST = inlist{$item}{<,$value}
APPEND = ${if def:value {, $item}{$item}}

${reduce {<, item1, item2, item1, item2, item3}\
{}\
{$value${if INLIST {}{APPEND}}}\
}

My test shows that it works, but i am not sure if some problem
is not hidden in it. Comments please?

regards


--
Slavko
https://www.slavino.sk/

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Reduce & inlist [ In reply to ]
D?a 29. februára 2024 6:42:38 UTC používate? Jasen Betts via Exim-users <exim-users@lists.exim.org> napísal:
>On 2024-02-28, Slavko via Exim-users <exim-users@lists.exim.org> wrote:

>I see what you mean, "${if inlist" doesn't seem to work inside "${reduce"

Not exactly, you can use inlist inside reduce just fain, you only cannot
use $value from reduce in positive case of inlist (as it has value from
inlist match, not from reduce).

>Embedded Perl is possibly a better approach, but it's been a decade
>since I used that for anything.

I am not very familiar with perl, but i will guess, that it is more heavy
than built in (simple) regex.

regards


--
Slavko
https://www.slavino.sk/

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Reduce & inlist [ In reply to ]
On Fri, Mar 01, 2024 at 11:39:57AM +0000, Slavko via Exim-users wrote:

> I am not very familiar with perl, but i will guess, that it is more
> heavy than built in (simple) regex.

There is definitely some overhead with the embedded perl approach,
but if you just mean the regexps themselves, they are almost 100%
compatible (the library exim uses for regexps is called PCRE with
good reason).

--
Ian

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Reduce & inlist [ In reply to ]
D?a 1. marca 2024 19:06:22 UTC používate? Ian Z via Exim-users <exim-users@lists.exim.org> napísal:

>There is definitely some overhead with the embedded perl approach,

Yes, i mean that overhead.

regards


--
Slavko
https://www.slavino.sk/

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/