MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Unsorted Union

  • To: mathgroup at
  • Subject: [mg61485] Re: Unsorted Union
  • From: "dkr" <dkrjeg at>
  • Date: Wed, 19 Oct 2005 23:07:42 -0400 (EDT)
  • References: <dj4p6t$gpt$>
  • Sender: owner-wri-mathgroup at


Consider the first element of x, call it x1. Using the definition of
the function f, it will generate the value x1 (and also store the value
f[x1] as Sequence[]).  Note that since this is the first time x1 has
been encountered in the mapping operation, there won't be a previously
stored value of f[x1].  Now as we proceed through the elements of x,
suppose we encounter x1 again.  Then mathematica will already have
stored the value f[x1], and will use it to generate the value
Sequence[], which effectively removes that x1 from the list.

Robert Schoefbeck wrote:
> Hello all,
> in the help section i found the following thing:
> UnsortedUnion[x_] := Module[{f}, f[y_] := (f[y] = Sequence[]; y); f/@x]
> It does just what it says:
> UnsortedUnion[{a,c,b,d,a,b}]={a,c,b,d}
> (ordinary Union would Sort the result)
> my question is: How does the definition work? I know all the syntax
> and i have been using these concepts for for some time now. But i cant
> figure out what this definition does.
> Robert

  • Prev by Date: Re: Unsorted Union
  • Next by Date: Re: Display sound but suppress graphics
  • Previous by thread: Re: Unsorted Union
  • Next by thread: Re: Unsorted Union