Re:Map

*To*: mathgroup at smc.vnet.net*Subject*: [mg29750] Re:[mg29740] Map*From*: Ranko Bojanic <bojanic at math.ohio-state.edu>*Date*: Sat, 7 Jul 2001 02:25:55 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

In [mg29740] Allan Hays wrote: >Ranko, >>b={{1,5,10},{25,0,{1,2,3,4}},{55,5,2001} >>If we try to apply a function g to levels 2 and 3 we get >>ClearAll[g] >>Map[g,b,{2,3}] >>{{g[1],g[5],g[10]},{g[25],g[0],g[{g[1],g[2],g[3],g[4]}]},{g[55],g[5],g[2001]}} >>but this is clearly not what we wanted because of the term >>g[{g[1],g[2],g[3],g[4]}]} >>The only way to obtain the correct result in this case is to make g listable >Not in this case:b={{1,5,10},{25,0,{1,2,3,4}},{55,5,2001}} >{{1,5,10},{25,0,{1,2,3,4}},{55,5,2001}} >Map[g,b,{-1}] >{{g[1],g[5],g[10]},{g[25],g[0],{g[1],g[2],g[3],g[4]}},{g[55],g[5],g[2001]}} Thanks,Allan This is what happens when one reads only the definition of Map and not the level specifications on page 1029. For the benefits of people like me, one should add this line to the definition of Map: Map[f, expr, {-1}] maps f to all symbols and objects in expr that have no subparts Ranko