MathGroup Archive 1996

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

Search the Archive

Programming: Replace Heads


I'm delited 2 have the opportunity 2 post another interesting prograMing 
problem.

Problem:
Given an abritrary expression, how to replace all heads to List?

my solution:
Map[ {(Sequence@@#)}&, expr, {0,-2}]

Example:

Clear[a,b,c,d,e,f,g]

f := ({a,b,c,d,e,g}[[Random[Integer, {1,6}] ]])

Array[ Hold at f, {3,2,3},1, Hold at f]//ReleaseHold

Map[ {(Sequence@@#)}&, %, {0,-2}]

Post your solutions. Please cc to me 2. I will write up a summary of 
solutions of PrograMMing Competition of last month.

 Xah
 xah at best.com; 74631.731 at compuserve.com
 http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
 Mountain View, CA, USA


  • Prev by Date: Re: mathematica 3.0 comments?
  • Next by Date: Re: simplify problem
  • Previous by thread: Re: PDE-Solving in Mathematica
  • Next by thread: Re: Programming: Replace Heads