MathGroup Archive 2005

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

Search the Archive

Re: Unsorted Union


Robert,

This was one of Carl Woll's ingenious routines.

The first time f hits a value y it establishes a definition but returns y.
The next time it hits a y the definition already exists and it returns
Sequence[]. An empty Sequence is simply elimited from a list of items. This
is very fast but it does use some storage space to store all the
definitions.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Robert Schoefbeck [mailto:schoefbeck at hep.itp.tuwien.ac.at]
To: mathgroup at smc.vnet.net


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: Desperate help
  • Next by Date: Re: Unsorted Union
  • Previous by thread: Re: Unsorted Union
  • Next by thread: Re: Unsorted Union