[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: func to remove dupes
From: |
John Graham-Cumming |
Subject: |
Re: func to remove dupes |
Date: |
Thu, 28 Jun 2007 15:28:18 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Stephan Beal wrote:
> 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))
You could always use the function 'uniq' which is in my GMSL. Here's
the definition:
uniq = $(if $1,$(call uniq,$(call chop,$1)) $(if $(filter $(call
last,$1),$(call chop,$1)),,$(call last,$1)))
John.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGg7dyLphrp73n/hARAqsxAKDnwu/NK4g3zpiS3cbLJC8k0r/1VQCgk6aW
YvCkcfP/zu/ur7PdMMtuMx0=
=h0a/
-----END PGP SIGNATURE-----