Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: Replace Heads
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Xah Lee

Posts: 171
Registered: 12/4/04
Re: Replace Heads
Posted: Nov 12, 1996 1:19 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

This is a summary on solutions to a programming problem "Replace Heads".

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

Example,
Clear[a,b,c,d,e,f,g,expr]
f := ({a,b,c,d,e,g}[[Random[Integer, {1,6}] ]])
expr = Array[ Hold@f, {3,2,3},1, Hold@f]//ReleaseHold
Map[ {(Sequence@@#)}&, expr, {0,-2}]

Solutions:
The following people

David B. Wagner" <dbwagner@princon.com>
Allan Hayes <hay@haystack>
Robert Villegas <villegas@wolfram.com>
Wouter <vdmcc@vandemoortele.be>
fransm@win.tue.nl (Frans Martens)

Gave the simple solution:

Apply[ List, expr, {0,-2}]

---

Yokoi Takahisa <yokoi@skk.is.tohoku.ac.jp>
expr //. (head:_) [args___] :> List[args] /; (List =!= head)

jpk@apex.mpe.FTA-Berlin.de (Jens-Peer Kuska)
expr //. any_?(List=!=# &)[args___] :> List[args]


Robby Villegas took the problem one step futher and considered cases
where expr contain heads that are not atoms, or whether you want your
expr remain unevaluated. Robby Villegas rank among the tops who
understand Mathematica language in DEPTH. Read his messages.

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







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.