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: Programming: Replace Heads
Replies: 1   Last Post: Nov 9, 1996 2:02 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Xah Lee

Posts: 171
Registered: 12/4/04
Programming: Replace Heads
Posted: Nov 6, 1996 12:49 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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@f, {3,2,3},1, Hold@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@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.