hi Stavros
I would like to use flatten with outermap,
I wrote newflatten dunction.
(%i4) load("newflatten.lisp");
(%o4) newflatten.lisp
(%i5) nflatten([[[a,b,c],d],[e,f]],1);
(%o5) [[a, b, c], d, e, f]
(%i6) nflatten([[[a,b,c],d],[e,f]]); /*default level 3*/
(%o6) [a, b, c, d, e, f]
(%i7) nflatten([[[a,b,c],d],[e,f]],2);
(%o7) [a, b, c, d, e, f]
how do you think?
gosei furuya
2007/6/4, Stavros Macrakis <macrakis at alum.mit.edu>:
>
> 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
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>