Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: List to infix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113057] Re: List to infix
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Tue, 12 Oct 2010 04:27:17 -0400 (EDT)
  • References: <i8ukkl$oc7$1@smc.vnet.net>

My brute force approach would be:

ToExpression[StringReplace[ToString[mylist], ", " -> "~"]]

Cheers -- Sjoerd

On Oct 11, 11:16 am, Hugo Touchette <hugo.touche... at googlemail.com>
wrote:
> 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



  • Prev by Date: Programing tips: What is faster?
  • Next by Date: Re: local variables - Module, For loop
  • Previous by thread: List to infix
  • Next by thread: Re: List to infix