MathGroup Archive 2010

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

Search the Archive

Re: List to Expression

Close, but no cigar:

{a, {b, {c, d}}} /. List -> Compose



expr = {a, {b, {c, d}}};
k = Depth@expr;
Replace[expr, List -> Compose, {0, k - 2}, Heads -> True]


expr //. {{a_, b_List} :> a[b], List -> Sequence}

a[b[c, d]]


On Thu, 31 Dec 2009 02:17:33 -0600, Spell <l_sharonj at> wrote:

> Hellp,
> I am having trouble converting a list into an "expression". For example  
> suppose I have the following list expression.
>    l = {a, {b, {c, d}}}
> When I evaluate the FullForm version, I get an output with List as the  
> Head.
>  List[a,List[b,List[c,d]]]
> But, I would like the following output instead: a[b[c,d]], wondering how  
> this would be accomplised.
> PS:
> Essentially, I have a FunctionSet with various functions in it. And  
> would like to generate a tree of functions, from the FunctionSet. So,  
> say I have functions from a to d in the set. Then, I can generate  
> something like: d[a[b], c[d[a[b]]].
> Thank you.

DrMajorBob at

  • Prev by Date: Re: More /.{I->-1} craziness
  • Next by Date: Re: bar chart ticks not placed well?
  • Previous by thread: Re: List to Expression
  • Next by thread: Database Challenge