• To: mathgroup at smc.vnet.net
• Subject: [mg5213] Re: [mg5161] Programming: Replace Heads
• From: yokoi at skk.is.tohoku.ac.jp (Yokoi Takahisa)
• Date: Fri, 15 Nov 1996 03:22:34 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```My solution is

See below:
========================================================
In[188]:=
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

Out[190]=
d[c[a[b[1, 1, 1], e[1, 1, 2], e[1, 1, 3]],
b[a[1, 2, 1], e[1, 2, 2], a[1, 2, 3]]],
e[b[e[2, 1, 1], g[2, 1, 2], g[2, 1, 3]],
e[b[2, 2, 1], g[2, 2, 2], e[2, 2, 3]]],
c[e[g[3, 1, 1], e[3, 1, 2], c[3, 1, 3]],
g[e[3, 2, 1], a[3, 2, 2], a[3, 2, 3]]]]

Out[191]=
{{{{1, 1, 1}, {1, 1, 2}, {1, 1, 3}},
{{1, 2, 1}, {1, 2, 2}, {1, 2, 3}}},
{{{2, 1, 1}, {2, 1, 2}, {2, 1, 3}},
{{2, 2, 1}, {2, 2, 2}, {2, 2, 3}}},
{{{3, 1, 1}, {3, 1, 2}, {3, 1, 3}},
{{3, 2, 1}, {3, 2, 2}, {3, 2, 3}}}}
========================================================

At  1:34 96/11/06 -0500, Xah Lee wrote:
Lee>Problem:
Lee>Given an abritrary expression, how to replace all heads to List?
Lee>
Lee>my solution:
Lee>Map[ {(Sequence@@#)}&, expr, {0,-2}]
Lee>
Lee>Example:
Lee>Clear[a,b,c,d,e,f,g]
Lee>f := ({a,b,c,d,e,g}[[Random[Integer, {1,6}] ]])
Lee>Array[ Hold at f, {3,2,3},1, Hold at f]//ReleaseHold
Lee>Map[ {(Sequence@@#)}&, %, {0,-2}]

*  Yokoi Takahisa <yokoi at skk.is.tohoku.ac.jp>
**  Graduate School of Information Science,
***  Tohoku Univ. <Tonpei>, Sendai, Japan

```

• Prev by Date: Problem with ReadList[]
• Next by Date: Re: Break a List into Individual Elements?