Re: List to Expression
- To: mathgroup at smc.vnet.net
- Subject: [mg106078] Re: [mg106055] List to Expression
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Fri, 1 Jan 2010 05:32:36 -0500 (EST)
- References: <200912310817.DAA24881@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
Close, but no cigar:
{a, {b, {c, d}}} /. List -> Compose
a[b[c[d]]]
ditto:
expr = {a, {b, {c, d}}};
k = Depth@expr;
Replace[expr, List -> Compose, {0, k - 2}, Heads -> True]
Perfect:
expr //. {{a_, b_List} :> a[b], List -> Sequence}
a[b[c, d]]
Bobby
On Thu, 31 Dec 2009 02:17:33 -0600, Spell <l_sharonj at hotmail.com> 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 yahoo.com