help-make
[Top][All Lists]
Advanced

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

Re: filter and filter-out functions do they preserve order


From: Tagomi Tagomi
Subject: Re: filter and filter-out functions do they preserve order
Date: Fri, 14 Aug 2009 20:57:00 +0100

On Fri, Aug 14, 2009 at 6:01 PM, Nicholas Mc Guire <address@hidden> wrote:
>
> On Fri, 14 Aug 2009, Krzysztof Cieniuch wrote:
>
> > Hi,
> >
> > Short question as in subject does filter function preserves original
> > elements order
> > I did some tests like:
> > org:= a b c d e
> > res:=$(filter a d c,$(org))
> > $(info $(res))
> >
> > and this prints  a c d so it looks like it preserves order but can I
> > relay on that
> > or is this just coincidence in my simple example ?
> >
> If you need to rely on order then simply use sort to ensure lexical
> order - then you don't need to bother with possible implementation
> details (the info page does not say anything about preserving order)
>
> hofrat

Hmm maybe I wasn't clear enough or maybe example was misleading or both :-)
back to question what I meant is if after filtering the filtered items
preserve original order
any order it doesn't and in my case it will never be lexical order.
more examples

org:= foo  fee fie foe fum bar bla
res:=$(filter bar foo,$(org))
$(info $(res))

I get "foo bar" as you can see filtered items preserve original order
, my question is is this just coincidence
or can I relay on filter to preserve order.

If you interested here is background for this question
The original problem I'm dealing with  in my make build system is
library path ordering
I want to define order of library paths so in my init Makefile I
specify order e.g.
/opt/pkg1/lib /opt/pkg2/lib /usr/local/lib/ /usr/lib

and then even if users specify different order I can then reorder list
using my order list here is code snip
#this is defined in header file included by all makefiles
_LIBS_PATH_ORDER:=/opt/pkg1/lib /opt/pkg2/lib /usr/local/lib/

#users in their makefiles can specify lib paths
LIB_PATH:=/foo/bar /usr/local/lib/  /opt/pkg1/lib

#then in ma footer makefile included by all makefiles that generates
rules based on user variable settings
#I have soemthing like this
_to_order:=$(filter $(_LIBS_PATH_ORDER),$(LIB_PATH))
_rest:=$(filter-out $(_LIBS_PATH_ORDER),$(LIB_PATH))

LIB_PATH:=$(filter $(_to_order),$(_LIBS_PATH_ORDER))
LIB_PATH+=$(_rest)

so at the and in LIB_PATH  I moved items that are on _LIBS_PATH_ORDER
to the front of LIB_PATH and!! in  order they are listed
in _LIBS_PATH_ORDER variable . But if and only if filter preserve
original list order

Thanks
Chris




reply via email to

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