List to infix
- To: mathgroup at smc.vnet.net
- Subject: [mg113017] List to infix
- From: Hugo Touchette <hugo.touchette at googlemail.com>
- Date: Mon, 11 Oct 2010 05:16:12 -0400 (EDT)
Hi,
A problem about infix notation. In simple terms, I want to transform
the list
{1, Plus, 3, Times, 5, Plus, 5}
into the infix form
1~Plus~3~Times~5~Plus~5
to get a numerical result (here 25). Is there an easy way to do this?
The lists I'm working with are actually much longer, so I want
something efficient.
I've tried using Infix[mylist,"~"], but the ~ there is a string, not
the infix operator. In the end, I simply wrote
ListOperation2[l_] := Module[{res, i},
res = l[[1]];
Do[
res = res~l[[i]]~l[[i + 1]]
, {i, 2, Length[l], 2}];
res
]
This works, but I thought there might be a more efficient way to do
things.
Thanks in advance for any help.
oguh