help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Find duplicates in a list


From: Rakesh Sharma
Subject: RE: Find duplicates in a list
Date: Tue, 29 Jul 2014 02:02:01 -0700

Hi Sam,

Here's another method, this time uses the recursive nature of user-defined 
functions of GNU make. I'd like to add that this is the preferred way, as the 
order of elements as in the original list is maintained.

The algo is very straightforward: we invoke the function "dupp" with an input 
list. the first thing
that dupp does is check whether the list was empty? if empty, then the 
recursion stops. For a non-empty list, it checks if there was just all of one 
element in the list. if y,
then again the recursion stops. The real action begins when there are 2 or more 
element
in the list, whereby it picks up the first one checks whether it is duplicated 
in the list. if not, 
then it discards the first element, re-builds the list by discarding the first 
element from the list
and invoking "dupp" on that re-constructed list. (in case the first element was 
found to be occurring more than once, then that element is remembered, removed 
from the list, & "dupp" called on the re-constructed list. That's all.

#########################################################################
# Usage: $(call dupp,input_list)
dupp = $(if $1,\
               $(if $(filter-out 1,$(words $1)),\
                   $(if $(filter 1,$(words $(filter $(firstword $1),$1))),\
                       $(call dupp,$(wordlist 2,$(words $1),$1)),\
                       $(firstword $1)$(call dupp,$(filter-out $(firstword 
$1),$1)))))

$(info Original list             => $(LISTx))
$(info Duplicates only list => $(strip $(call dupp,$(LISTx))))
#########################################################################

HTH

Thanks,
Rakesh

From: address@hidden
To: address@hidden
CC: address@hidden
Subject: RE: Find duplicates in a list
Date: Mon, 28 Jul 2014 04:09:12 -0700




Hi Sam,

LISTx := A A B C D D E
LISTd := $(strip \
                $(foreach v,$(sort $(LISTx)),\
                    $(if $(filter-out 1,$(words $(filter $(v),$(LISTx)))),\
                        $(v))))
$(info My make version=$(MAKE_VERSION))
$(info Original list   => $(LISTx))
$(info Duplicates list => $(LISTd))


This gives out the following:

My make version=4.0
Original list   => A A B C D D E
Duplicates list => A D

Thanks,
Rakesh

> Date: Sun, 27 Jul 2014 11:58:59 +0200
> From: address@hidden
> To: address@hidden
> Subject: Find duplicates in a list
> 
> Hi all.
> 
> I'm trying to find a way to detect duplicate items in a list without
> escaping to a shell.
> 
> Consider the following:
> 
> list := A B C A D C
> 
> In the list above A and C is duplicated.
> I would like to find a way so I can find which items are duplicated and print 
> them out.
> 
> The solution should preferably work with gmake 3.81 and even better in make 
> 3.80
> 
> Thanks in advance,
> 
>       Sam
> 
> 
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make
                                                                                
  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]