Re: A Bug in Flatten?
- To: mathgroup@smc.vnet.net
- Subject: [mg11214] Re: A Bug in Flatten?
- From: Xah Lee <xah@best.com>
- Date: Mon, 2 Mar 1998 23:11:05 -0500
Ted Ersek, Here's a simulation of Flatten and FlattenAt. I havn't tested them or studied them in depth. Soon I'll be come to them and there will be implementations with basic constructs. Quick Note: you can have non-atomic Head in expr as in Flatten[expr,f[x][g]] and it still works... Clear[flatten]; flatten::"usage" "flatten simulates the build-in function Flatten. Example: \ flatten[f[1,f[2,f[3,f[4,5]]]],2,f]"; flatten[expr_]:õatten[expr,Infinity,Head@expr]; flatten[expr_,n_Integer]:õatten[expr,n,Head@expr]; flatten[expr_,Infinity]:õatten[expr,Infinity,Head@expr]; flatten[expr_,0,h_]:ápr; flatten[expr_,1,h_]:f[Head@#Ýh,Sequence@@#,#]&)/@expr; flatten[expr_,n_Integer,h_]:õatten[flatten[expr,n-1,h],1,h]; flatten[expr_,Infinity,h_]:òxedPoint[(flatten[#,1,h]&),expr]; Clear[flattenAt]; flattenAt::"usage" "flattenAt simulates the build-in function FlattenAt. Example: \ flattenAt[Array[List,{3,2}],2]"; flattenAt[expr_,parts_]:jpAt[(Sequence@@#&),expr,parts]; Xah, xah@best.com http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html "morality abets evil"