[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
func to remove dupes
From: |
Stephan Beal |
Subject: |
func to remove dupes |
Date: |
Thu, 28 Jun 2007 14:54:13 +0200 |
User-agent: |
KMail/1.9.7 |
Hi, all!
i've created a function which removes duplicates from a list while
keeping their relative order untouched (code is below). While it
appears to work fine, i'm not at all happy with the temp var it uses
($(remove-dupes-holder)). Is there anyone out there who would care to
take a crack at improving this function, so that it doesn't need the
extra variable (or any improvement, for that matter)?
####################################################
# $(call remove-dupes,list)
# Returns a string equal to list with duplicate entries
# removed. It does not sort the list.
remove-dupes-holder :=
remove-dupes-impl = $(if $(filter $(1),$(remove-dupes-holder)),,\
$(eval remove-dupes-holder+=$1))
remove-dupes = $(strip \
$(eval remove-dupes-holder:=)\
$(foreach ENTRY,\
$(if $1,$1,),\
$(call remove-dupes-impl,$(ENTRY)))\
$(remove-dupes-holder))
##################################
# Test code:
ifeq (1,1)
remove-dupes-test:
# remove-dupes: $(call remove-dupes,c b a a b c)
# remove-dupes: <$(call remove-dupes,a b A a b B c a c c b d C)>
# remove-dupes: <$(call remove-dupes,$(strip ))>
# # remove-dupes: <$(call remove-dupes)>
else
all:
endif
$ make -f remove-dupes.make
# remove-dupes: c b a
# remove-dupes: <a b A B c d C>
# remove-dupes: <>
--
----- stephan beal
http://www.wanderinghorse.net
signature.asc
Description: This is a digitally signed message part.
- func to remove dupes,
Stephan Beal <=