join N lists ?



Your specification isn't entirely clear.  Do you want the set of distinct
elements, or the list of all elements? Also, you use the term "join" -- does
that mean something other than simply the set-theoretic union?  (It means
something quite different in database theory...)

If the set of distinct elements:

       xreduce('union,map('setify, l))

or somewhat less efficiently

       setify(xreduce('append, l))

If the list of all elements:

       xreduce('append, l)

xreduce is a very useful function (thank you, Barton!) and is very generally
useful.  On the other hand, flatten has very specialized uses, and is easy
to misuse:

If any of the elements of the lists are themselves sets, it includes their
elements (not the set itself), e.g.

     m_join( [ [ {a,b,c} , d], [e,f] ] ) => [a,b,c,d,e,f]    NO!
            should be [  {a,b,c} , d, e, f  ]

This is because you're using the "flatten" function.  The flatten function
is only really appropriate for recursive representations.  So, for example,
if you represent a tree as

       mytree: node(a,node(node(b,c),d),e)$

to get all the leaves under the top node:

       flatten(mytree) => node(a,b,c,d,e)

If, on the other hand, you have a well-defined structure, e.g. a list of
lists, then flatten is just an invitation to bugs such as the above.
Flatten is very rarely the right thing.

        -s