MathGroup Archive 2010

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

Search the Archive

List to infix

  • To: mathgroup at
  • Subject: [mg113017] List to infix
  • From: Hugo Touchette <hugo.touchette at>
  • Date: Mon, 11 Oct 2010 05:16:12 -0400 (EDT)


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


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]];
   res = res~l[[i]]~l[[i + 1]]
   , {i, 2, Length[l], 2}];

This works, but I thought there might be a more efficient way to do

Thanks in advance for any help.


  • Prev by Date: If without else
  • Next by Date: changing variables in place
  • Previous by thread: Re: If without else
  • Next by thread: Re: List to infix