MathGroup Archive 1996

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

Search the Archive

Programming: Replace Heads

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5161] Programming: Replace Heads
  • From: Xah Lee <xah at best.com>
  • Date: Wed, 6 Nov 1996 01:34:08 -0500
  • Organization: Best Internet Communications
  • Sender: owner-wri-mathgroup at wolfram.com

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